問題描述
是否可以檢測到用戶何時點擊了瀏覽器的后退按鈕?
我有一個 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
這篇關于跟蹤用戶何時點擊瀏覽器上的后退按鈕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!