使用JavaScript渲染android的SVG [英] Using javascript to render svg in android
问题描述
我有几个SVG文件和一些.js文件。
我想用.js文件渲染SVG文件。
I have a few svg files and some .js files. I'd like to render the svg files using the .js files.
我现在做的是:
1.把所有的SVG和js文件置入资产
2.与本书写code:
What I have done now is: 1. Put all the svg and js files into assets 2. And written this code:
final String mimeType = "text/html";
final String encoding = "utf-8";
final String html = "<p><img height=\"600px\" width=\"600px \"src=\"file:///android_asset/drawing2.svg\" /></p>";
WebView wv = (WebView) findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
SVG的显示。但.js文件没有任何效果可言。如何让他们一起工作?任何指针/帮助AP preciated。
谢谢你。
The svg is shown. But the .js files have no effect at all. How do I make them work together? Any pointers / help is appreciated. Thanks.
推荐答案
有关JavaScript并没有在图像在任何浏览器中运行的安全性和隐私的原因。你不得不使用&LT;对象&gt;
,&LT;嵌入&GT;
或&LT ; IFRAME方式&gt;
标签来获取脚本的工作
For security and privacy reasons javascript does not run in images in any browser. You'd have to use an <object>
, <embed>
or <iframe>
tag to get scripting to work.
这篇关于使用JavaScript渲染android的SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!