可能的WebView OnCreateWindow使弹出窗口(对话框样式)?像Android浏览器对话框、弹出窗口、样式、浏览器

2023-09-06 06:49:55 作者:眼里住着星辰

当我preSS一个按钮在ebay.com在我的WebView这code:

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

HTML按钮:

html of button:

input id="addPicturesBtn" name="addPicturesBtn" type="button" value="Add pictures" class="button" onclick="ebay.run(this.id,'onclick');return false;" onkeydown="ebay.run(this.id,'onkeydown');return false;" title="Add pictures"

如果该键是我的WebView里面pssed $ P $,它从我的WebView到Android浏览器发送的新窗口。但是,如果同一个按钮是在Android浏览器就弹出这个凉爽的对话框类型的弹出窗口pssed $ P $(见图片)

If this button is pressed inside my webview, It sends the new window from my webview to the android browser. But if the same button is pressed from within the android browser it pops up this cool dialog type popup window (see picture)

我想打开弹出式的窗口,在eBay上像浏览器一样,如果这个按钮是我的WebView里面pssed $ P $。因此,它可以由用户封闭它们返回到我的背后的应用程序时,他们已完成了弹出

I would like to open the popup style window on eBay like the browser does, if this button is pressed inside my webview. So that it can be closed by the user to return them to my app behind it when they are done with the popup.

这可能吗?

下面是我到目前为止有:

Here is what I have so far:

   webChromeClient = new WebChromeClient() {
    @Override
    public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
        WebView childView = new WebView(Ebay.this);
        final WebSettings settings = childView.getSettings();
        settings.setJavaScriptEnabled(true);
        childView.setWebChromeClient(this);
        childView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
        transport.setWebView(childView);
        resultMsg.sendToTarget();

    return true;
    }
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
            result.confirm();
            return true;

       }

我缺少的东西?

Am I missing something?

下面是Android浏览器弹出的画面(我试图让我的web视图从按钮启动的ebay.com):

Here is a picture of the android browser popup (That I'm trying to get my webview to launch from the button on ebay.com):

推荐答案

您可以做他的方式:

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

顺便说一句,小心2.3版本,它有一个相应的错误,仅供参考))

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