Warning not showing from web view in android?

I am using a sample provided by Google to demonstrate the two way communication between JavaScript and Java,

ref [1]:

http://code.google.com/p/apps-for-android/source/browse/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java

Functionality is working fine. I can call the JavaScript function from Java and call the Java function from JavaScript.

The problem is that I am using a warning inside the JavaScript function that it won but the functionality inside the function is working correctly.

Why is alert("test") inside the JavaScript function not showing up in Android. I am loading JavaScript in a web-view . When I press the button on Android I call the function, but it does not appear.

If anyone knows the problem, help me help.

thanks

+6
source share
4 answers
 setContentView(R.layout.main); WebView webview = (WebView) findViewById(R.id.webview); WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webview.requestFocusFromTouch(); webview.setWebViewClient(new WebViewClient()); webview.setWebChromeClient(new WebChromeClient()); webview.loadUrl("file:///android_asset/test.html"); 

this code works perfectly and shows me a warning. and this is my test.html

 <html> <head> <script type="text/javascript"> function show_alert() { alert("Hello! I am an alert box!"); } </script> </head> <body> <input type="button" onclick="show_alert()" value="Show alert box" /> </body> </html> 
+13
source

By adding the following two lines, my JavaScript works:

 mWebview.setWebViewClient(new WebViewClient()()); mWebview.setWebChromeClient(new WebChromeClient()); 
+1
source

Use the following mehtod,

 WebView wv=new WebView(this); wv.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message,JsResult result) { //Required functionality here return super.onJsAlert(view, url, message, result); } 
0
source

Just use WebChromeClient. He will do everything.

 mWebview.setWebChromeClient(new WebChromeClient()); 

He will work.

0
source

Source: https://habr.com/ru/post/891262/


All Articles