1.设置js弹窗控制器

webView.JsDialogHandler = this;  //js弹窗控制

this表示本类对象,所以本类要实现IJsDialogHandler接口

 

2.实现IJsDialogHandler接口接口方法

   public bool OnJSAlert(IWebBrowser browser, string url, string message)
        {
            MessageBox.Show(message);
            return true; //阻止js弹
        }

        public unsafe bool OnJSConfirm(IWebBrowser browser, string url, string message, bool* retval)
        {
            DialogResult result = MessageBox.Show(message, "提示", MessageBoxButtons.YesNo);
            bool value = result == DialogResult.Yes ? true : false;
            //   retval = (bool *)GCHandle.Alloc(value).AddrOfPinnedObject().ToPointer(); //获取托管内存地址,异常
            // retval = &value; //改变指针失败
            *retval = value;
            return true;
        }

        public unsafe bool OnJSPrompt(IWebBrowser browser, string url, string message, string defaultValue, bool* retval, ref string result)
        {
            //交互消息
            string r = string.Empty;
            this.Invoke(new Action(() =>
            {
                r = Microsoft.VisualBasic.Interaction.InputBox(message, "提示", defaultValue);
            }));
            result = r;

            if (result == defaultValue)
            {
                *retval = false;
            }
            else
            {
                *retval = true;
            }
            return true;
        }

 

相关文章:

  • 2021-11-02
  • 2021-11-14
  • 2021-11-17
  • 2021-05-29
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-25
  • 2021-11-27
  • 2022-12-23
  • 2021-10-16
  • 2021-11-27
相关资源
相似解决方案