Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE8 What is tiggering beforeunload event

I have an issue that is only a problem in IE8, go figure.

I have a anchor tag with an onclick attribute

<a href="javascript:void(0);" onclick="foo();">Click Me</a>

and then foo is declared elsewhere:

<script type="javascript/text">
     function foo(){
       //do some work
       return false;
     }
</script>

After foo is called, my onbeforeunload handler is being executed, and I have no idea why.

I have had other instances, if the foo function does not return false, it triggers the beforeunload event in IE, but even with this function returning false, it still hits my onbeforeunload handler and I can't figure out why.

Is there any way to find out what is triggering it. I have viewed the event object inside my onbeforeunload handler, but it doesn't not seem to give me and relevant info.

Any Ideas?

like image 886
MattoTodd Avatar asked Feb 18 '11 22:02

MattoTodd


People also ask

What triggers Beforeunload?

The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point. This event enables a web page to trigger a confirmation dialog asking the user if they really want to leave the page.

What is Onunload event?

The onunload event occurs once a page has unloaded (or the browser window has been closed). onunload occurs when the user navigates away from the page (by clicking on a link, submitting a form, closing the browser window, etc.).

Can I use Onbeforeunload?

This feature is deprecated/obsolete and should not be used.


1 Answers

Change it to

<a href="#" onclick="return foo();">Click Me</a>

or

<a href="#" onclick="foo();return false;">Click Me</a>
like image 184
amit_g Avatar answered Oct 12 '22 15:10

amit_g