跟踪用户何时点击浏览器上的后退按钮 [英] Track when user hits back button on the browser

查看:19
本文介绍了跟踪用户何时点击浏览器上的后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检测到用户何时点击了浏览器的后退按钮?

我有一个 Ajax 应用程序,如果我可以检测到用户何时点击了后退按钮,我就可以返回相应的数据

任何使用 PHP、JavaScript 的解决方案都是首选.地狱任何语言的解决方案都很好,只需要我可以翻译成 PHP/JavaScript 的东西

从下方剪切和粘贴:

哇,所有优秀的答案.我想使用 Yahoo,但我已经在使用 Prototype 和 Scriptaculous 库并且不想添加更多的 ajax 库.但它使用了 iFrames,这给了我一个很好的指针来编写我自己的代码.

解决方案

有多种方法可以做到,但有些方法只能在某些浏览器中使用.我最清楚的是在页面上嵌入一个几乎不可见的微小 iframe.当用户点击后退按钮时,iframe 会向后导航,您可以检测并更新您的页面.这里是另一种解决方案.>

您可能还想查看 Gmail 之类的源代码,看看他们是如何做到的.

这里是 一个库,可以满足您的需求方式

Is it possible to detect when the user clicks on the browser's back button?

I have an Ajax application and if I can detect when the user clicks on the back button I can display the appropriate data back

Any solution using PHP, JavaScript is preferable. Hell a solution in any language is fine, just need something that I can translate to PHP/JavaScript

Edit: Cut and paste from below:

Wow, all excellent answers. I'd like to use Yahoo but I already use Prototype and Scriptaculous libraries and don't want to add more ajax libraries. But it uses iFrames which gives me a good pointer to write my own code.

解决方案

There are multiple ways of doing it, though some will only work in certain browsers. One that I know off the top of my head is to embed a tiny near-invisible iframe on the page. When the user hits the back button the iframe is navigated back which you can detect and then update your page. Here is another solution.

You might also want to go view source on something like gmail and see how they do it.

Here's a library for the sort of thing you're looking for by the way

这篇关于跟踪用户何时点击浏览器上的后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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