window.onbeforeunload = function ()
{
var shallIAlertUser = Do_Whatever(); //get boolen value
if (shallIAlertUser) {
//this will alert user
return 'Are you sure?';
}
else {
//this wont
window.onbeforeunload = undefined;
}
};
More Related Contents:
- How to capture the browser window close event?
- jQuery Event Keypress: Which key was pressed?
- Definitive way to trigger keypress events with jQuery
- Trying to detect browser close event
- Can I call jQuery’s click() to follow an link if I haven’t bound an event handler to it with bind or click already?
- How to copy text to the client’s clipboard using jQuery? [duplicate]
- What is the difference between the mouseover and mouseenter events?
- Difference between “change” and “input” event for an `input` element
- How to force reloading a page when using browser back button?
- Resize event for textarea?
- How do you log all events fired by an element in jQuery?
- Jquery: change event to input file on IE
- Why should y.innerHTML = x.innerHTML; be avoided?
- Preventing click event with jQuery drag and drop
- Attach an event in a child iframe to a handler in the parent window
- Javascript with jQuery: Click and double click on same element, different effect, one disables the other
- Changing the keypress
- How can I retain the scroll position of a scrollable area when pressing back button?
- Detect if browser is running on an Android or iOS device
- jQuery prevent change for select
- Can I resize the browser window?
- Drop event not firing in chrome
- How to unbind a specific event handler
- How to check if css value is supported by the browser?
- Why web browsers don’t have jQuery built in? [duplicate]
- Capture event onclose browser
- List all javascript events wired up on a page using jquery
- Change Height based on Browser Size/Resize
- Is it possible to catch browser’s File Open/Save dialog event using Javascript
- addEventListener to iFrame