Running a method on browser close tab or browser exit

百般思念 提交于 2020-02-02 07:49:45

问题


Is there an action handler I can use in Javascript+Angular+JQuery that makes it possible to schedule a method to be executed just before a tab is closed in the web browser?

By close I mean quitting the browser or closing the tab or crashing or anything...


回答1:


Yeah, you just bind the the beforeunload on the window object.

angular.element($window).bind("beforeunload", exitHandler)


来源:https://stackoverflow.com/questions/19287644/running-a-method-on-browser-close-tab-or-browser-exit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!