Adam Moore![]()
The beforeunload event is not standard, yet it is useful enough to support as well as we can. Browsers are not consistent about how the event operates, and some browsers do not support it at all. This module supplants any existing DOM0 onbeforelistener because DOM2 style listeners won't work across the A grade at this time.
You can attempt to prevent the user from leaving the page by setting the returnValue property on the event object. The user will be presented with a dialog to see whether or not they want to allow you to prevent the page navigation. If a message is included in the returnValue property, it is added to the dialog in addition to what the browser normally displays.
The following code will attempt to prevent the navigation away from the page. The user will be presented with a dialog that will include the text provided in e.returnValue.
<script src="http://yui.yahooapis.com/3.5.0pr4/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2012.03.28-20-16'
}).use('gallery-beforeunload', function(Y) {
Y.on('beforeunload', function(e) {
e.returnValue = "Please don't go.";
});
});No forum posts for this module.
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info