gpt4 book ai didi

javascript - 关闭浏览器选项卡时执行操作(Javascript)

转载 作者:行者123 更新时间:2023-11-30 13:32:23 26 4
gpt4 key购买 nike

我希望能够在浏览器窗口/选项卡关闭时执行一些操作。这应该使用 Javascript 来完成。有什么建议吗?

最佳答案

使用 onBeforeUnload 处理程序。看这个:

Handle Browser close in JavaScript?

https://developer.mozilla.org/en/DOM/window.onbeforeunload

更新:

看这个:

http://www.megasolutions.net/javascript/Accessing-new-URL-in-onbeforeunload---or-similar-effect-by-other-means-9527.aspx

If there was a way to catch the unload and prevent it happening then popup adverts everywhere would use it to prevent you closing the popups.

A different approach would be to use the onload event for your page to go through all tags in the page and add an onclick handler which does what you want.

关于javascript - 关闭浏览器选项卡时执行操作(Javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6283723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com