In IE, the onbeforeunload event is fired for links that do not unload the page

I am writing a plugin for CMS (umbraco) and I want to attach a warning dialog box 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; }); 

IE has a problem because IE fires the onbeforeunload event when any link is clicked, even if the link does not move.

Here I gave an example: http://jsfiddle.net/DETTG/8/

Note. I do not control ajax controls in the property area, they are written by third parties.

+6
source share
2 answers

Perhaps this page will help you?

+1
source

If you remove "href" then it will work. But then you will need to style it as a link element and add the onclick attribute if you want to execute the 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> 
+1
source

Source: https://habr.com/ru/post/899091/


All Articles