javascript - return in an event function results in alert pop-up -
i following book on javascript. page puzzles me following: http://javascriptbook.com/code/c06/html5-events.html.
when user pressed "next" button event fires. code specifies event listener:
window.addeventlistener('beforeunload', function(event) { var message = 'you have changes have not been saved'; (event || window.event).returnvalue = message; return message; })
this code results in alert , offers me stay on page or leave. don't syntax here. thought alerts made alert()
function. going or here? help
this code returns message, browser takes care of confirming user navigation( or close) event, why browser specific alert.
window.addeventlistener('beforeunload', function(event) { var message = 'you have changes have not been saved'; (event || window.event).returnvalue = message; return message; // alerts message. });
if try below code, doesnt returns message, won't confirmation alert box, can still capture event , stuff.
window.addeventlistener('beforeunload', function(event) { //var message = 'you have changes have not been saved'; //(event || window.event).returnvalue = message; localstorage.eventcaptured = 'eventcaptured without alert'; // gets saved localstorage //return message; })
Comments
Post a Comment