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

后端 未结 2 773
栀梦
栀梦 2021-01-07 08:38

When I press a button with this code on ebay.com in my webview:

html of button:

input id=\"addPicturesBtn\" name=\"addPicturesBtn\" type=\"button         


        
2条回答
  •  不思量自难忘°
    2021-01-07 09:21

    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))

提交回复
热议问题