Note that there are some explanatory texts on larger screens.

plurals
  1. PONavigate away script not working
    primarykey
    data
    text
    <p>So, making an web portal for work. Boss wants me to log the user out if they navigate away from the page. Found this tutorial: <a href="http://kbeezie.com/cross-browser-exit-pop/" rel="nofollow">http://kbeezie.com/cross-browser-exit-pop/</a></p> <p>I used the jquery example and inserted it into a couple pages to test it out. I'm using asp.net/C# for development. Here's the basic layout of the page, including my script:</p> <pre><code>&lt;%@ Page ... %&gt; &lt;asp:Content .. &gt; &lt;/asp:Content&gt; &lt;asp:Content .. &gt; //my navigate away function &lt;script type="text/javascript"&gt; function PopIt() { return "Are you sure you want to leave?"; } $(document).ready(function () { window.onbeforeunload = PopIt; $("a").click(function () { window.onbeforeunload = null; }); }); &lt;/script&gt; &lt;div&gt; &lt;table&gt;&lt;/table&gt; //other stuff &lt;/div&gt; &lt;/asp:Content&gt; </code></pre> <p>When I click a link on our web portal, the navigate away script works, it doesn't pop up because we're clicking on an internal link. But, if I keep navigating around on the site, after 2 or 3 clicks eventually if I click on an internal link it will ask me if I'm sure I want to leave. Can anyone tell me why this is happening?</p> <p>Edit: We have jquery referenced on every page, so this is not the issue.</p> <p>Edit: Here's a <a href="http://jsfiddle.net/rVUbP/1/" rel="nofollow">JSFiddle</a> that works. When you click on the link nothing happens but when you navigate away it prompts.</p>
    singulars
    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.
 

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