如何检测用户是否点击了“返回”按钮。按键 [英] How to detect if the user clicked the "back" button

查看:492
本文介绍了如何检测用户是否点击了“返回”按钮。按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户进入历史记录1时...如何检测到?然后,警告用户点击回来!

When the user goes history-back-1...how do I detect that? And then, alert "the user clicked back!"

使用绑定(最好是jquery)

Using binds (and jquery preferably)

推荐答案

你一般不能(浏览器安全限制)。您可以判断用户是否离开了页面(onbeforeunload,onunload fire),但除非您已将页面设置为允许,否则您无法分辨他们的去向。

You generally can't (browser security restriction). You can tell if the user navigates away from the page (onbeforeunload, onunload fire) but you can't tell where they went unless you've set up your page to allow it.

HTML5引入了HTML5 History API;在符合标准的浏览器中, onpopstate 如果用户导航回您网站上较早的页面,则会触发事件。

HTML5 introduces the HTML5 History API; in conforming browsers, the onpopstate event will fire if the user navigates back to an earlier "page" on your site.

这篇关于如何检测用户是否点击了“返回”按钮。按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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