possible WebView OnCreateWindow to make popup window(Dialog style)? like android browser

十年热恋 提交于 2019-12-01 01:36:07

Use javascript interface. Combine javascript with java and make custom dialog in java At first, enable javascript

webview.getSettings().setJavaScriptEnabled(true);

On second, you need to add javascript interface

wv.addJavascriptInterface(new DemoJavaScriptInterface(), "js");

And third, load url;

webview.loadUrl("javascript:[javascript function name here]()");

Here is some code for you, hope this can help https://github.com/scottagarman/Android-JavaScript-Interface-Example

Code credit go to the developer called "scottagarman" .

You can do it his way:

public void onCreate(Bundle savedInstanceState){
  ....
  webView.getSettings().setJavaScriptEnabled(true);
  webView.addJavascriptInterface(new MyJSInterface(), "myappname");
  webView.loadUrl("http://mysite.com/"); // or some local asset
  ....
}

public class MyJSInterface{

....
 public void popup(){

//  AlterDialog etc.

 }
....

}


HTML from your website:

window.onload = function(){
   window.myappname.popup();
}

I wish it would be useful for you...

By the way, be careful with 2.3 version it had a corresponding bug, just FYI))

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!