jQuery 或 JS 处理浏览器后退按钮

发布于 2024-10-06 14:31:42 字数 130 浏览 0 评论 0原文

有什么想法如何通过 jQuery 拦截浏览器后退按钮,以便我可以运行我的事件函数吗? 我不需要使用 jQuery BBQ 或 jQuery Address,只需要阻止默认行为并在一些动画之后运行它。

谢谢你!

d

Any ideas how to intercept the browser back button via jQuery, so I can run my event function?
I don't need to use jQuery BBQ or jQuery Address, only prevent the default behaviour and run it later after some animate.

Thank you!

d

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国产ˉ祖宗 2024-10-13 14:31:42

没有尝试过,但我想这就是你想要的。

window.onbeforeunload = function () {
   // stuff do do before the window is unloaded here.
}

使用 jQuery 你可以尝试 .unload() 函数

卸载事件发送到窗口
当用户离开时的元素
从页面。这可能意味着其中之一
很多事情。用户可以有
单击链接离开页面,
或在地址中输入新的 URL
酒吧。前进和后退按钮将
触发事件。关闭浏览器
窗口将导致事件
触发。即使页面重新加载也会
首先创建一个卸载事件。

Have not tried but i guess this do what you want.

window.onbeforeunload = function () {
   // stuff do do before the window is unloaded here.
}

with jQuery you could try the .unload() function

The unload event is sent to the window
element when the user navigates away
from the page. This could mean one of
many things. The user could have
clicked on a link to leave the page,
or typed in a new URL in the address
bar. The forward and back buttons will
trigger the event. Closing the browser
window will cause the event to be
triggered. Even a page reload will
first create an unload event.

葮薆情 2024-10-13 14:31:42

在 jQuery 领域:

$(window).unload( function () { /*code here*/ });

编辑 - 有一个括号而不是右括号

编辑 - 删除了额外的分号

In jQuery land:

$(window).unload( function () { /*code here*/ });

EDIT- There was a parentheses instead of a close bracket

EDIT - Removed Extra Semicolin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文