简体   繁体   中英

Safari OnUnload event on user exit

I am calling a JavaScript function from the code behind by adding it the the OnUnload event, because I need it to fire when the user exits the window or navigates to a new page.

bodyName.Attributes.Add("OnUnload", "JSFucntionName");

This function is firing on all browsers when a user refreshes or navigates to a new page, and it is firing on IE, Chrome, and Firefox when a user exits, but not on Safari.

Does Safari not call the OnUnload event when the user exits the window? Or is there a work-around for calling a JavaScript function in Safari on a user exit?

You can try calling onpagehide instead as a workaround, I believe it is called when the the page is closed as well:

window.onpagehide = function() {
    // some code here.
};

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