Solved in Is it possible to display a custom message in the beforeunload popup?
Original question
I'm curently using Firefox ESR 45.3.0, and I've written a small test page:
<html>
<body>
<script type="text/javascript">
window.onbeforeunload = function() {return "foo"};
</script>
<p>content</p>
</body>
</html>
erroneous behavior:
- load any page
- load this test page (can also be reproduced via "file:///...")
- click browser back
- the confirm dialog is not shown
correct behavior:
- load any page
- load this test page
- click inside the window
- click browser back
- the confirm dialog is shown
I've also played around with the console (developer tools), trying to set focus on window or body, still not working without clicking the page. My original problem page is longer, instead of 7. you can also scroll the page by mousewheel, this also "activates" the onbeforeunload handler.
Strange, looks like a Firefox bug, do you have any hints how to deal with this problem?
Regards, Gunnar
Update 1
Working with e.returnValue does not fix the problem, I've tested it in the test page shown above.
The test page is very simple, my original javascript code in the original problem page is copied from some other question/answer and goes like
function checkModelChanged(modelChanged, confirmText)
{
if (modelChanged === true)
{
var myEvent = window.attachEvent || window.addEventListener;
var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable
myEvent(chkevent, function(e) { // For >=IE7, Chrome, Firefox
(e || window.event).returnValue = confirmText;
return confirmText;
});
}
}
Update 2
The test page works as expected in Chrome 52.0.2743.116 m and Edge 38.14393.0.0 (EdgeHTML 14.14393). Browser back without "window interaction" shows the confirm dialog.
The original problem page is part of a Liferay Portlet (JSF 2.2 and Primefaces 5.3), and I've already tried javascript's scollIntoView and jQuery's animate (scrollTop) or trigger (click).