cefsharp重写默认js弹窗(alert/confirm/prompt)
生活随笔
收集整理的這篇文章主要介紹了
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;}?
更多專業前端知識,請上 【猿2048】www.mk2048.com
總結
以上是生活随笔為你收集整理的cefsharp重写默认js弹窗(alert/confirm/prompt)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 四、spring boot 1.5.4
- 下一篇: js实现字体和容器宽高随窗口改变