简体   繁体   中英

Something overwrites window.onbeforeunload in Javascript

Hello guys,

I have a strange problem with my ASP.NET 4.5 page. For some strange reason, my window.onbeforeunload function gets overwritten every time I load the page. Inside the debugger, I can clearly see that the right value is set in my head section, if I place a breakpoint there. However, after finishing the loading process of the site, the value changes to the following:

function (a){return typeof p!="undefined"&&(!a||p.event.triggered!==a.type)?p.event.dispatch.apply(h.elem,arguments):b}

I have no idea where this is coming from. This is my code from the head section of the page:

window.onbeforeunload = function (e) { return 'Do you really want to cancel?'; };

I'm using JQuery 2.1.3 as well as DevExpress 14.2 in my project. Any idea what could be responsible for this weird behavior?

Thanks in advance!

I actually found the answer where this is coming from thanks to @DavidTansey's hint. It's the Browser Link feature that was introduced in Visual Studio 2013. It looks like Browser Link uses some old jQuery library and overwrites various handlers.

So if you are having the same issue, please try to disable the feature (the menu is next to the browser selection in the tool bar). This should solve the problem.

I'm pretty sure that this problem wouldn't appear on a real server, because it would likely not use Browser Link.

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