2

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 flot 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

mdelolmo
  • 6,417
  • 3
  • 40
  • 58
elwis
  • 1,395
  • 2
  • 20
  • 34

1 Answers1

1

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.

mdelolmo
  • 6,417
  • 3
  • 40
  • 58
  • Thanks, perhaps it's impossible to include local javascript from code, it works well when using the mWebView.loadUrl("file:///android_asset/about.html") with included js. I noted that the loadData() function which I use in this case can't access resources on the network, so perhaps loadin all the three js files into the – elwis Feb 17 '11 at 09:53
  • @elwis, you may want to check my edited answer. Have you already read that? – mdelolmo Feb 17 '11 at 10:48
  • @mdelolmo : Yes i'm creating within the – penguru Apr 10 '12 at 10:11
  • http://stackoverflow.com/questions/3760626/how-to-write-files-to-assets-folder-or-raw-folder-in-android It seems it's not possible to write files in asset folder.. – penguru Apr 10 '12 at 10:12