sachin003 sachin003 - 1 month ago 12
Javascript Question

How to load JS & CSS from SDCARD with loadDataWithBaseURL() method

I have a .html, .js, .css files on SDCARD, in my case html file contents are in encrypted form. I'm loading html file in following steps :


  1. Read file content

  2. Decrypt all content

  3. Load all content into webview using below line :

    webView.loadDataWithBaseURL(relativePath, decFileContent, "text/html",
    "utf-8", null );


    here
    relativePath = "file:///mnt/sdcard/MyFolder/"



What happens?

It loads the decrypted content successfully, however not loading js & css files kept in relativePath folders named with JS/ & CSS/ respectively. It gives the following error dialog


"Sorry! your application not support to local storageError: SECURITY_ERR: DOM Exception 18"


Also, I searched for the above error & possible similar links are 1 & 2 in answers to these questions they have suggested to load js & css from assets folder. In my case I don't want load them from assets, I want to load them from SDCARD. Anybody have an idea how to achieve this?

Answer

Give the entire path of the HTML file, not just the directory path in relativePath.

Or you can also use loadUrl

http://developer.android.com/reference/android/webkit/WebView.html#loadUrl%28java.lang.String%29