简体   繁体   English

在不更改URL的情况下注入新的历史记录条目。像谷歌地图一样

[英]Injectng a new history entry without changing the url. Like google maps does

I'm trying to find the best approach not to break the back button in my javascript application. 我试图找到最好的方法,不要破坏我的JavaScript应用程序中的后退按钮。

In my research I'm trying to see what the state of the art is. 在我的研究中,我试图了解最先进的技术。 So I turned to google maps to see how it works. 所以我转向谷歌地图,看看它是如何工作的。

It does have back/forward functionality, but it doesn't change the url when generating a new history entry. 它具有后退/前进功能,但在生成新的历史记录条目时不会更改URL。 Try to go to http://maps.google.com/ , type NY and press enter. 尝试访问http://maps.google.com/ ,输入NY并按Enter键。 Now use the back button. 现在使用后退按钮。 No url change. 没有网址改变。

How do they do this? 他们如何做到这一点? I tried to figure it out but I have a hard time wading through outdated documentation about javascript history and IE6 tips. 我试图解决这个问题,但我很难浏览有关javascript历史和IE6技巧的过时文档。

Create a new history entry: 创建新的历史记录条目:

location.hash = 'new_history_entry';

Creating no history entry: 不创建历史记录条目:

location.replace('http://no/new/history/entry');

Google maps is using frames. 谷歌地图正在使用框架。 To verify it, run HttpFox. 要验证它,请运行HttpFox。 You'll get a HTML page with javascript in it. 你会得到一个带有javascript的HTML页面。 You can analyse it on your own, or just believe me that it works with frames. 你可以自己分析它,或者只是相信我它可以用于框架。

Lekensteyn's answer will not add the back/forward buttons in IE6, you need a frame for that. Lekensteyn的答案不会在IE6中添加后退/前进按钮,你需要一个框架。 jQuery History uses the onhashchange event if the browser supports it (all modern browsers do) if not it will add the appropriate backwards support needed (ie6 needs iframes, firefox 1, ie7 etc just need interval checks). jQuery History使用onhashchange事件,如果浏览器支持它(所有现代浏览器都支持),如果不是,它将添加所需的适当向后支持(ie6需要iframe,firefox 1,ie7等只需要间隔检查)。

YUI浏览器历史记录管理器这样的东西会做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM