Note that there are some explanatory texts on larger screens.

plurals
  1. POonbeforeunload event not firing in my code, but other examples work?
    primarykey
    data
    text
    <p>As usual, I want to alert users to unsaved changes when leaving a page. I have this test page:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Testing&lt;/title&gt; &lt;script language="JavaScript1.1" src="https://127.0.0.1:8443/scripts/base.js"&gt;&lt;/script&gt; &lt;script language="JavaScript1.1" src="https://127.0.0.1:8443/scripts/edit.js"&gt;&lt;/script&gt; &lt;script language="JavaScript1.1"&gt;window.onbeforeupload=moveAway&lt;/script&gt; &lt;/head&gt; &lt;body onLoad="init()"&gt; &lt;a href="http://www.google.com"&gt;Google&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The moveAway function is defined in "edit.js" like this:</p> <pre><code>function moveAway () return "foo";&lt;br&gt; } </code></pre> <p>The event doesn't fire, or at least it just leaves the page silently (using IE8, Firefox 15, and Chrome 20). I've tried breakpointing the function in Firebug and it never gets to the breakpoint. I've tried it from the web server (an SSL server, the test version of which runs at 127.0.0.1:8443) and I've tried opening the file directly with the browser (which is why I used absolute URLs for the first two &lt;script&gt; tags). I've tried removing the "src=" attribute from the script tags.</p> <p>On the other hand, this page has an example which does work (at least in Firefox):</p> <p><a href="http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm" rel="nofollow">http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm</a></p> <p>There is also a very similar example at MSDN which also works:</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms536907%28VS.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms536907%28VS.85%29.aspx</a></p> <p>I really can't see the difference between what they do and what I'm doing. can anyone tell me why their code works and mine doesn't?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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