Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript警报消息在android应用程序中不起作用_Javascript_Android_Webview - Fatal编程技术网

javascript警报消息在android应用程序中不起作用

javascript警报消息在android应用程序中不起作用,javascript,android,webview,Javascript,Android,Webview,我已经创建了一个带有简单webview功能的android应用程序。在webview加载的html页面中,我使用以下脚本 var message="!!YOU CANNOT COPY ANY TEXT OR IMAGE FROM THIS APP!"; function clickIE4() { if (event.button==2) { alert(message); return false; } } function cli

我已经创建了一个带有简单webview功能的android应用程序。在webview加载的html页面中,我使用以下脚本

var message="!!YOU CANNOT COPY ANY TEXT OR IMAGE FROM THIS APP!";
  function clickIE4()
  {
    if (event.button==2)
    {
      alert(message);
      return false;
    }
  }
  function clickNS4(e)
  {
    if (document.layers||document.getElementById&&!document.all)
    {
      if (e.which==2||e.which==3)
      {
        alert(message);
        return false;
      }
    }
  }

  if (document.layers)
  {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
  }
  else if (document.all&&!document.getElementById)
  {
    document.onmousedown=clickIE4;
  }
    document.oncontextmenu=new Function("alert(message);return false")
//for disable select option
//document.onselectstart = new Function("alert(message);return false");

当我在android webview应用程序中打开它时,它不会显示警告消息。当我在普通浏览器中打开它时,它可以正常工作。

您需要创建
WebChromeClient
并设置为
WebiView
。还重写
onJsAlert
方法

     WebChromeClient webChromeClient = new WebChromeClient() {
                @Override
                public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {

                    new AlertDialog.Builder(context)
                            .setMessage(message)
                            .setPositiveButton(android.R.string.ok,
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            result.confirm();
                                        }
                                    })
                            .create()
                            .show();

                    return true;
                }
    }

  webView.setWebChromeClient(webChromeClient);

为webview添加java代码。。但是哪个功能对我有用呢???谢谢!仅供参考,我了解到有3个不同的JS对话框:JsAlert、JsPrompt和JsConfirm。因此,对于周围的任何人来说,也许这些信息会有所帮助-我必须为我试图解决的问题覆盖JsConfirm。