Reputation: 1762
I'm using the jQuery code below to launch an overlay div and it works great in Chrome and Firefox -- but in IE9 it launches a window "Do you want to leave this page?" and also says "message from web page: null". The window continues to come up on every single link clicked on after that until you end the session by logging out (it's a Codeigniter based app)
Any insight as to what may be causing this would be much appreciated.
EDIT: Offending code is:
window.onbeforeunload = function() { saveFormData(); return false; }
Upvotes: 4
Views: 5007
Reputation: 15753
Answer from Scunliffe helped me fixing this issue in the following way -
Added the below line at end of all my JavaScript code.
window.onbeforeunload = function(){}
You can try this in the console section of IE Developer Tools if want to have a quick test.
Again I am not sure how this will impact things in your code. So do test all your code properly if anything is broken. The code that will break might be related to any listeners that are attached to page unload or onbeforeunload events. In my case there weren't any :)
Hope it helps.
Upvotes: 0
Reputation: 63596
I don't know where the exact issue in your page is but I believe you've encountered the Joys of IE
and the onbeforeunload
event.
In Internet Explorer it treats all navigation link clicks as to be "leaving" the page and thus if you have an onbeforeunload event defined you will get the confirmation message (presuming your code, or the CodeIgnitor framework has attached a handler)
The problem is that a link like this:
<a href="javascript:doSomething();">Do something on this page without leaving</a>
will trigger IE to believe the user is leaving the page.
The way I got around this was to do the following (ugly but it worked).
In my small page (a popup window) on the 4-5 links that were "internal" to the page I added a CSS class: class="internal"
then in my onbeforeunload
event I would check to see if the source element that triggered the event had the class set... and if so "ignore" throwing up my "Are you sure you want to leave?" type warning...
However on a "main" page with litterally 100's and 100's of links this would be very ugly to try and implement. - Best of luck.
Upvotes: 4