Javascript:更改浏览器后退按钮的功能 [英] Javascript : Change the function of the browser's back button

查看:129
本文介绍了Javascript:更改浏览器后退按钮的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在浏览器上设置用户的后退按钮,调用javascript函数而不是返回页面?

Is there a way to make the user's back button on their browser, call a javascript function instead of going back a page?

推荐答案

如果用户关注指向您网页的链接,则无法覆盖以下行为,单击返回会将其重新关闭。

You can't override the behaviour that if a user follows a link to your page, clicking Back will take them off it again.

但您可以制作JavaScript页面上的操作会将条目添加到历史记录中,就好像它们是对新页面的点击一样,并控制在这些点击的上下文中使用后退和前进进行的操作。

But you can make JavaScript actions on your page add entries into the history as though they were clicks to new pages, and control what happens with Back and Forward in the context of those clicks.

借助 Really Simple History 作为一个受欢迎的示例,JavaScript图书馆可以为您提供帮助。

There are JavaScript libraries to help with this, with Really Simple History being a popular example.

这篇关于Javascript:更改浏览器后退按钮的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆