Javascript:当页面被导航时检测到“返回”至 [英] Javascript: detect when page has been navigated "back" to
问题描述
假设我在浏览器中打开了一个页面,然后进入我的地址栏并输入另一个页面。然后我点击后退按钮进入我的原始页面。我想写一些Javascript代码,可以检测到这种情况并作出回应。
尽我所知,准备就绪
事件, onload
以及页面上的任何内联Javascript都会在此场景中重新执行。还有什么我可以做的吗?
跨浏览器支持在这里很重要。
编辑为了清楚起见:我假设的导航是页面A - >页面B - >返回页面A,我在哪里假设页面B可能或不可以在我的控制之下。 解决方案
http://benalman.com/projects/jquery-bbq-plugin/ 似乎很适合,如果你考虑一个Jquery插件。
Suppose I have a page open in a browser and I go to my address bar and enter another page. Then I hit the back button to go to my original page. I'd like to write some Javascript code that can detect this scenario and respond to it.
As best I can tell neither the ready
event, the onload
, nor any inline Javascript on the page itself is re-executed in this scenario. Is there anything else I can do?
Cross-browser support is important here. jQuery based solutions preferred but not required.
Edit for clarity: the navigation I'm assuming is Page A -> Page B -> back to page A where I'm assuming that Page B may or may not be under my control.
http://benalman.com/projects/jquery-bbq-plugin/ seems to be a good fit, if you consider a Jquery plugin.
这篇关于Javascript:当页面被导航时检测到“返回”至的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!