zoukankan      html  css  js  c++  java
  • cefsharp重写默认js弹窗(alert/confirm/prompt)

     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;
            }
  • 相关阅读:
    javaweb
    反射 day1
    JDBC-day1
    总结
    day5
    day4
    day3
    18.10.17 考试总结
    洛谷P2172 [bzoj] 2150 部落战争
    18.10.15 考试总结
  • 原文地址:https://www.cnblogs.com/hdwang/p/3922353.html
Copyright © 2011-2022 走看看