window.onbeforeunload = function() {
return 'You have unsaved changes!';
}
See the MSDN article on onbeforeunload
Also there is a similar question in SO
More Related Contents:
- How can I override the OnBeforeUnload dialog and replace it with my own?
- How to show the “Are you sure you want to navigate away from this page?” when changes committed?
- Prevent a webpage from navigating away using JavaScript
- Crossbrowser onbeforeunload?
- How to prevent closing browser window?
- window.onbeforeunload not working on the iPad?
- Way to know if user clicked Cancel on a Javascript onbeforeunload Dialog?
- Setting onbeforeunload on body element in Chrome and IE using jQuery
- Is there any way to use window.onbeforeunload on Mobile Safari for iOS devices?
- How to disable beforeunload action when user is submitting a form?
- Mozilla firefox not working with window.onbeforeunload
- Difference between onbeforeunload and onunload
- How to disable a “Reload site? Changes you made may not be saved” popup for (python) selenium tests in chrome?
- window.onbeforeunload in Chrome: what is the most recent fix?
- Browser waits for ajax call to complete even after abort has been called (jQuery)
- Reload the site when reached via browsers back button
- Javascript detect closing popup loaded with another domain
- How to display onbeforeunload dialog when appropriate?
- Is there an alternative method to use onbeforeunload in mobile safari?
- How would you overload the [] operator in javascript
- How to detect emoji using javascript
- Reverse array in Javascript without mutating original array
- What is innerHTML on input elements?
- JavaScript: Listen for attribute change?
- How to open a new window and insert html into it using jQuery?
- Phonegap InAppBrowser display pdf 2.7.0
- javascript regex for password containing at least 8 characters, 1 number, 1 upper and 1 lowercase [duplicate]
- Rails, javascript not loading after clicking through link_to helper
- Use external javaScript library in angular application
- window.close equivalent in Phonegap with InAppBrowser