I am using a webbrowser control to navigate to a site that has a JavaScript unload event. When I attempt to navigate elsewhere, a popup appears prompting me if I want to "Stay On Page" or "Leave Page". If I keep attempting to navigate away, a COMException is thrown.
How can I prevent popups like these from occurring in my webbrowser?
How can I disable Javascript when I am ready to navigate to another webpage?
You can do something like this (Delphi code):
var
WrkIHTMLWindow2: IHTMLWindow2;
WrkIHTMLWindow2Disp: IHTMLWindow2Disp;
begin
WrkIHTMLWindow2 := IHTMLDocument2Disp(WrkIWebBrowser2.Document).parentWindow;
if WrkIHTMLWindow2.QueryInterface(IHTMLWindow2Disp, WrkIHTMLWindow2Disp) = S_OK then
if not VarIsNull(WrkIHTMLWindow2Disp.onbeforeunload) then
WrkIHTMLWindow2Disp.onbeforeunload := NULL;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.