简体   繁体   中英

Capturing the browser tab reload and tab close functionality

I want to call an ajax to other pages on the browser or tab close. When we reload tab or close tab it calls onbeforeUnload and onUnload events.
If I reload page either by pressing ctrl+r or by pressing enter in address bar it should reload page without any prompt and if I click close of browser or tab or I press ctrl+w keys it should prompt that "Changes you made might be lost" and if user click leave it should close tab and call an ajax, else it should stay on page.
Can anyone help me with this?
Thanks in advance

Most of the browsers intentionally block popups triggered in onbeforeunload, for known reasons .

But if you want to preserve users' data from erasing, you can engage window.localstorage property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM