Repeated "Message from webpage: null" alert in IE

I am using the jQuery code below to launch the overlay div and it works fine in Chrome and Firefox, but in IE9 it launches the "Do you want to leave this page?" Window. and also says "message from web page: null". The window still appears on every single link after which you end your session by logging out (this is a Codeigniter based app)

Any insight into what might be causing this would be much appreciated.

EDIT: Breaking code:

window.onbeforeunload = function () {saveFormData (); return false; }

+3


source to share


2 answers


I don't know where exactly the problem is on your page, but I believe that you are facing joys IE

and onbeforeunload

.

In Internet Explorer, it handles all clicks on navigation links to "leave" the page, and thus if you have an onbeforeunload event defined you will receive a confirmation message (assuming your code or CodeIgnitor is attached to the handler)

The problem is that a link like this:

<a href="javascript:doSomething();">Do something on this page without leaving</a>

      



will cause IE to believe that the user is leaving the page.

The way I got around this was the following (ugly, but it worked) had to be done.

On my little page (popup) on 4-5 links that were "internal" in the page, I added a CSS class: class="internal"

and then in my onbeforeunload

event I would check if the source element that triggered the event had a set of classes .. . and if so "ignore" throws my "Are you sure you want to leave?" warning type ...

However, on a "home" page with 100 and 100 links, it would be very ugly to try and implement. - Good luck.

+3


source


The answer from Scunliffe helped me solve this problem like this:

Added bottom line at the end of all my JavaScript code.

window.onbeforeunload = function(){}

      



You can try this in the IE Developer Tools console section if you want to do a quick test.

Again I'm not sure how this will affect things in your code. So check all your code correctly if something is broken. The code break can be associated with any listeners attached to the page unload or onbeforeunload events. In my case, they were not there :)

Hope it helps.

0


source







All Articles