简体   繁体   中英

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.

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>

也许这个页面可以帮到你?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM