Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This message is shown by the underlying MSHTML engine if the web page handles <a href="http://msdn.microsoft.com/en-us/library/ie/ms536907%28v=vs.85%29.aspx" rel="nofollow noreferrer">window.onbeforeunload</a> event. Usually, it's there for a reason, to let the user know his/her input hasn't been saved or submitted yet. The prompt suppression script from <a href="https://stackoverflow.com/questions/10348692/supress-the-are-you-sure-you-want-to-leave-this-page-popup-in-the-net-webbrow">the answer you linked</a> doesn't work for cases when the page uses <code>addEventListener("beforeonload", handler)</code> or <code>attachEvent("onbeforeunload", handler)</code>. I don't think there's a reliable way of doing this, without resorting to low-level Windows hooks.</p> <p><strong>[UPDATE]</strong> The following script (look for "Inject this script") is a hack which aggressively suppresses the page's own handlers for <code>onbeforeunload</code> event, via <code>setInterval</code>. It should work in 99% of cases, but it still leaves a gap for the page to override <code>onbeforeonload</code> right before navigating away.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt; &lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript"&gt; window.attachEvent("onbeforeunload", function (ev) { window.event.returnValue = "onbeforeunload via window.attachEvent()"; }); window.addEventListener("beforeunload", function (ev) { window.event.returnValue = "onbeforeunload via window.addEventListener()"; }); window.onbeforeunload = function (ev) { window.event.returnValue = "onbeforeunload via window.onbeforeunload"; }; &lt;/script&gt; &lt;script type="text/javascript"&gt; // // Inject this script // (function () { var onbeforeunloadHandler = function (ev) { if (ev) { if (ev.stopPropagation) ev.stopPropagation(); if (ev.stopImmediatePropagation) ev.stopImmediatePropagation(); ev.returnValue = undefined; } window.event.returnValue = undefined; } var handler = null; var intervalHandler = function () { if (handler) window.detachEvent("onbeforeunload", handler); // window.attachEvent works best handler = window.attachEvent("onbeforeunload", onbeforeunloadHandler); // handler = window.addEventListener("beforeunload", onbeforeunloadHandler); // handler = window.onload = onbeforeunloadHandler; }; window.setInterval(intervalHandler, 500); intervalHandler(); })(); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;a href="http://www.example.com"&gt;Go away&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>To inject this script with Delphi, you'd probably need to resort to low-level <code>WebBrowser/MSHTML</code> COM interfaces, like <code>IWebBrowser2</code>, <code>IHTMLDocument2</code>, <code>IHTMLScriptElement</code>, in a very similar way it's done in the linked answer. With some more efforts, the same can also be done via late binding, using <code>IDispatch::GetIDsOfNames</code> and <code>IDispatch::Invoke</code> only. If you're asking for exact Delphi code, I don't have one. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload