'In IE the onbeforeunload event is fired for links that don't unload the page

I am writing a plugin to a CMS (umbraco) and I wish to attach a warning dialog to various actions on the page, one such action is clicking a link (JavaScript links), in most browsers the following code works well:

$(".propertypane").delegate("a, a div", "click", function () { window.onbeforeunload = confirmNavigateAway; });

The following is an issue in IE because IE appears to trigger onbeforeunload event when any link is clicked, even though the link is not navigating away.

I've set up an example here: http://jsfiddle.net/DETTG/8/

Note: I do not have control over the ajax controls within the propertypane, they're written by third parties.



Solution 1:[1]

Maybe this page will help you?

Solution 2:[2]

If you remove "href" then it will work. But then you would need to style it as a link element and add the attribute onclick if you want to execute a function. Here is the updated version: http://jsfiddle.net/DETTG/34/

<a onclick="alert('do some ajax');" style="color:blue; text-decoration:underline; cursor:pointer">javascript</a>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 StKiller
Solution 2 Ernesto