Web 浏览器控制阻止您确定要离开此页面吗
Web Browser Control prevent Are you sure you want to leave this page
我有一个用于导航到另一个页面的应用程序,一种网络浏览器,问题是某些网页显示 "Are you sure you want to leave this page ? " 对话。我想完全删除它。它应该在没有这个对话的情况下开始导航。我试过了,
WebBrowser.ScriptErrorsSuppressed = True
截图:http://image.prntscr.com/image/5d1adcbd60794f22b5ad7baf736b29f2.png
我也试过禁用 javascript 但没有成功。任何帮助,将不胜感激。
您需要使用可以找到的不安全本地方法 here 来拦截新的 window 事件
JavaScriptonbeforeunload事件负责处理此类消息。通过将其设置为 null
为:
window.onbeforeunload = null;
您可以阻止其处理程序代码来自 运行。
这会起作用:
Dim doc As HtmlDocument = WebBrowser1.Document
Dim head As HtmlElement = doc.GetElementsByTagName("head")(0)
Dim s As HtmlElement = doc.CreateElement("script")
s.SetAttribute("text", "function cancelOut() { window.onbeforeunload = null; }")
head.AppendChild(s)
WebBrowser1.Document.InvokeScript("cancelOut")
我有一个用于导航到另一个页面的应用程序,一种网络浏览器,问题是某些网页显示 "Are you sure you want to leave this page ? " 对话。我想完全删除它。它应该在没有这个对话的情况下开始导航。我试过了,
WebBrowser.ScriptErrorsSuppressed = True
截图:http://image.prntscr.com/image/5d1adcbd60794f22b5ad7baf736b29f2.png
我也试过禁用 javascript 但没有成功。任何帮助,将不胜感激。
您需要使用可以找到的不安全本地方法 here 来拦截新的 window 事件
JavaScriptonbeforeunload事件负责处理此类消息。通过将其设置为 null
为:
window.onbeforeunload = null;
您可以阻止其处理程序代码来自 运行。
这会起作用:
Dim doc As HtmlDocument = WebBrowser1.Document
Dim head As HtmlElement = doc.GetElementsByTagName("head")(0)
Dim s As HtmlElement = doc.CreateElement("script")
s.SetAttribute("text", "function cancelOut() { window.onbeforeunload = null; }")
head.AppendChild(s)
WebBrowser1.Document.InvokeScript("cancelOut")