拦截JavaScript卸载事件 [英] Intercept JavaScript unload events
问题描述
onclick
。在处理程序中,触发了一个卸载事件,例如通过分配 window.location
。 任务:我需要以检测事件处理程序是否将卸载页面。我如何添加另一个拦截卸载事件的事件处理程序,并将其存储在变量中,而不是触发它?
更新
这是一个解释,由于混乱。我写了一个使用Selenium 2的Java应用程序来提取有关用户事件的所有信息。这是很容易完成,除了卸载。我必须等待拉,才能最终卸载页面。
如果你需要防止页面卸载看这个帖子:
我如何在JS中停止卸载页面(导航)
如果您需要跟踪页面卸载,可以使窗口的卸载事件(您的页面将不会退出,直到此请求完成)
如果您需要跟踪哪个自定义事件处理程序卸载页面,您将必须跟踪当前的事件处理程序,然后执行上述解决方案之一。
Assumed that i have web pages with an arbitrary amount of elements which have an event handler attached, let's say onclick
. In the handler an unload event is triggered, for example by assigning window.location
.
The task: I need to detect if an event handler will unload the page. How can i add another event handler which intercepts the unload event and stores it in a variable instead of triggering it?
Update
Here is an explenation, due to confusion. I have written a Java application that uses Selenium 2 to pull all information about user events. This is easily done, except for unloads. I have to wait for the pull before i can finally unload the page.
if you need to prevent page unload see this post: How do I stop a page from unloading (navigating away) in JS?
If you need to track page unloads, you can make a synchronous xhr request (tip set async=false) during your window's unload event (your page will not exit until this request finishes)
if you need to track which custom event handlers unload the page, you will have to track the current event handler and then do one of the above mentioned solutions.
这篇关于拦截JavaScript卸载事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!