[英]overriding javascript function in a webview
I want to integrate an existing website into my webview but also override a javascript function that exists on this website with my own version? 我想将现有网站集成到我的webview中,还想用我自己的版本覆盖该网站上存在的javascript函数? Then I can use the java-javascript bridge.
然后,我可以使用java-javascript桥。 I have tried using the following but it seems to execute the function only
我尝试使用以下内容,但似乎仅执行该功能
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webView.loadUrl("javascript: (function myFunc() { "
+ "alert('overriden alert ha!');"
+ "})()");
}
});
You need 你需要
replace("<head>","<head>"+"your code");
replace("<head>","<head>"+"your code");
webview.loadDataWithBaseURL("", string, "text/html", "utf-8", "");
webview.loadDataWithBaseURL("", string, "text/html", "utf-8", "");
加载经过编辑的HTML webview.loadDataWithBaseURL("", string, "text/html", "utf-8", "");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.