1. 程式人生 > >[Android-Bug] Android WebView XMLHttpRequest cannot load file from android asset folder

[Android-Bug] Android WebView XMLHttpRequest cannot load file from android asset folder

WebView呼叫assets裡的html,其中jquery的ajax請求報錯誤:Cross region XHMLHttpRequest…

解決方式:

// settings for webview
mWebView = (WebView)findViewById(R.id.activity_main_webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.getSettings
().setAllowFileAccess(true); mWebView.getSettings().setAllowContentAccess(true); mWebView.getSettings().setAllowFileAccessFromFileURLs(true); mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true); //load file mWebView.loadUrl("file:///android_asset/www/index.html");