I am trying to load webviews in a view pager.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = null;
v = inflater.inflate(R.layout.webview_layout, container, false);
myWebView = (WebView)v.findViewById(R.id.webview1);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
myWebView.loadUrl("file:///android_asset/web/index.html");
myWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
myWebView.loadUrl("javascript:testFunction()");
}
}
}
After loading the page, a javascript function is called in onPageFinished()
While scrolling at normal speed the webpages are loading and the javascript is executed.
But while scrolling at high speed the following exception is occured.
> 09-06 14:29:06.750: E/Web Console(8272): Uncaught ReferenceError:
> testFunction is not defined:1
testFunction() is
function testFunction(){
console.log("TestFuntion");
}
Please help...
I was getting
Uncaught Reference Error: JavascriptInterfaceName is not defined
on every second startup of my hybrid application on 4.3 and below, and so I did this thanks to @Abi in myWebChromeClient
class:And it works! Thank you very much!
try something like this and make changes as per your requirement
webview code
javascript interface
webpage code
EDIT
I had a fix on this
just set webChromeClient and catch the error and reload the page...