Firstly, I am very green in the programming world, so forgive me if my question does not have a solution in any part. I am currently trying to create an application for which links cannot be executed in WebView - or in another browser. I managed to set the following two links: In Android Webview, can I change the DOM webpage? and Titanium Appcelerator Quickie: disable links in Webview and create the following working code:
private class WebClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { view.loadUrl("javascript:document.body.innerHTML = document.body.innerHTML.replace(/<a.*href=/gi,'<a href=\"#\" _url=');"); } }
The above snippet is placed before the onCreate method and references the onCreate method as follows:
viewer = (WebView) findViewById(R.id.wv_engine); viewer.setWebViewClient(new WebViewClient()); viewer.loadUrl(content);
Now the code works ... But only after the requested web page has been loaded a second time. The first time I launch WebView, example.com has all of its links whole, clickable, and executable. Using the cradle, exiting WebView and entering it again disables all links, changing
<a href="http://www.example.com">link</a>
to
<a href="#" _url="http://www.example.com">link</a>
Now I am a theory about which I am not at all sure (I am not a programmer). I believe that JavaScript runs slowly, which leads to the fact that link manipulations never occur. This is why it works a second time instead with a cache. I got this thought from reading this discussion . However, I do not know how to fix it.
So my question is: how can I make sure that none of the links on the displayed website can be used? Is there any way to do manipulations before the site appears?
Thank you for your time and effort. This is a truly amazing community;)