This works perfectly for me in both Chrome and Safari:
<html><body><p>Test</p>
<script>window.onbeforeunload = function() { return "Sure?"; }</script>
</body></html>
When I try to close the window, I get the prompt.
More Related Contents:
- Get the real width and height of an image with JavaScript? (in Safari/Chrome)
- How can I force WebKit to redraw/repaint to propagate style changes?
- Is it possible to display a custom message in the beforeunload popup?
- Video auto play is not working in Safari and Chrome desktop browser
- :not() selector not behaving the same between Safari and Chrome/Firefox
- Unexpected token ILLEGAL in webkit
- Date parsing in javascript is different between safari and chrome
- Open Safari / Google Chrome developer tools programmatically from JavaScript
- Setting onbeforeunload on body element in Chrome and IE using jQuery
- Prevent Address-Bar hiding in mobile Browsers
- Distinguish Chrome from Safari using jQuery.browser
- Webkit bug with `:hover` and multiple adjacent-sibling selectors
- Preventing cache on back-button in Safari 5
- javascript large integer round because precision? (why?)
- Disabling same-origin policy in Safari
- Difference between onbeforeunload and onunload
- What happens when localStorage is full?
- Safari ignoring tabindex
- Hiding textarea resize handle in Safari
- How to disable a “Reload site? Changes you made may not be saved” popup for (python) selenium tests in chrome?
- Selecting text on focus using jQuery not working in Safari and Chrome
- Chrome, Safari ignoring max-width in table
- What heuristics do browsers use to cache resources not explicitly set to be cachable?
- chrome/safari display border around image
- Silence net::ERR_CONNECTION_REFUSED
- Chrome and Safari XSLT using JavaScript
- WebKit CSS content Unicode bug?
- Chrome & Safari Error::Not allowed to load local resource: file:///D:/CSS/Style.css
- Select size attribute size not working in Chrome/Safari?
- WebDriverException: Message: Service /content/chromedriver unexpectedly exited. Status code was: -6 with ChromeDriver Google Colab and Selenium