开发者

android webview include javascript

Might be a silly question but I don't know how to include the src URL for my javascript into the Webview?

I build a huge html tag in code, passing in variables, and then print them using flo开发者_如何转开发t diagrams. The javascript files reside in my asset folder, so in static html page I simply refer to them as file:///android_asset/jquery.flot.js.

But how do I do that when it's all built up by code? This doesn't seem to work

"<script language=\"javascript\" type=\"text/javascript\" src=\"file:///android_asset/jquery.flot.js\"></script>" +

Regards


First make sure your references are right, second... research if you can include a local Javascript, cause I'm not sure of that.

But why don't you try generating the Javascript code (read from the file) whitin the <script> tag? Maybe it could be a solution.

Edited:

Have you had a look to this? It's on WebView's public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) method description:

Note for post 1.0. Due to the change in the WebKit, the access to asset files through "file:///android_asset/" for the sub resources is more restricted. If you provide null or empty string as baseUrl, you won't be able to access asset files. If the baseUrl is anything other than http(s)/ftp(s)/about/javascript as scheme, you can access asset files for sub resources.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜