I am using Firefox ESR 45.2 and I'm using window.onbeforeunload to give the user a choice to leave the page or stay on it, when he leaves the window. This is my code:
window.onbeforeunload = function ( e ) {
var e = e || window.event ;
// For Firefox and IE
if ( e ) {
e.ReturnValue = 'Any string' ;
}
// For Safari
return 'Any string' ;
}
But the problem is that in Firefox, unless I open the developer tools once and then close it, the code does not work. I also looked at this question
Why does JavaScript only work after opening developer tools in IE once?
And I removed all console.logs. But still the window.onbeforeunload does not work. What could be the problem?