In my app, am loading a local html which is residing in SD card as
String extPath = getExternalFilesDir(null).toString();
String html = getHtml(extPath+File.separator+fileName); //it just reads html file and returns content as string
webvu.loadDataWithBaseURL("file://"+extPath+File.separator,html ,
"text/html","UTF-8", null);
the html file loaded in the web view (webvu) tries to load another html file with $.load ajax call
$.load("base.html",function(){ ... });
ajax load is throwing the below error. How can I resolve this
XMLHttpRequest cannot load file:///storage/emulated/0/Android/data/com.example.sdcardwebview/files/sec.html. Cannot make any requests from null. at null:1
I finally figured out the solution
The null origin issue happens only in JB, which supposedly has a webview based on new webkit which implements stricter same origin policy.
Hence the code in question works perfectly fine on all version of android below JB. To get the code work on JB, all we need to do is change web view settings. Just call
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With