[英]Can't execute javascript in the webview
I've tried so many things and it seems that nothing is working... In every one solution I see that I can enable javascript and execute whatever I want after the webpage is loaded in the webview. 我已经尝试了很多事情,似乎什么也没有用...在每个解决方案中,我都可以启用javascript并在将网页加载到webview之后执行所需的任何操作。 However my code seems to be wrong and I really can`t see why..
但是我的代码似乎是错误的,我真的不明白为什么。
Tried to make a new class and override the onPageFinished()
试图创建一个新类并覆盖
onPageFinished()
@Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:$(document).ready(function() { $('.logo').css('display','none'); });");
}
Not working! 不工作!
Tried to hardcode it : 试图对其进行硬编码:
final WebView webview = (WebView)findViewById(R.id.web_view);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
webview.loadUrl("javascript:<script>$(document).ready(function() { $('.pages').css('display','none!important'); });</script>");
}
});
webview.loadUrl("https://zdravenmonitor.bg/");
Also not working.. 也不能用..
What its problem ? 它有什么问题?
尝试这个:
view.loadUrl("javascript:(function() { $(document).ready(function() { $('.logo').css('display','none'); }); })()");
Try this: 尝试这个:
Define a function in your javascript file as 在您的javascript文件中将一个函数定义为
function finishPage(){
//Do your work
}
And call it from WebChromeClient as: 并从WebChromeClient调用为:
webview.loadUrl("javascript:finishPage()");
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.