Window.location.hash 需要语法帮助
我的网站位于 http://visualise.ca/,当您通过单击缩略图加载帖子时,它将加载使用ajax在页面内发布帖子。当您关闭帖子时,它会使用此代码将网址更改回 http://visualise.ca/,而无需重新加载页面:
$("#close").live("click", function(event) {
$("#board").fadeOut("slow");
$("#board-wrapper").slideUp("slow");
$("html,body").delay(1000).animate({scrollTop: 0}, 300);
window.location.hash = "";
window.history.pushState(null,null,site_url+"/");
return false;
});
但在 IE8 中,它会将其更改回 http://visualise.ca/# 而不是 http://visualise.ca/。有没有办法纠正这个问题并确保将其更改为 http://visualise.ca/ ?
My website is available at http://visualise.ca/ and when you load a post by clicking a thumbnail it will loads the post within the page using ajax. When you close the post it uses this code in order to change the url back to http://visualise.ca/ without reloading the page:
$("#close").live("click", function(event) {
$("#board").fadeOut("slow");
$("#board-wrapper").slideUp("slow");
$("html,body").delay(1000).animate({scrollTop: 0}, 300);
window.location.hash = "";
window.history.pushState(null,null,site_url+"/");
return false;
});
but in IE8 it changes it back to http://visualise.ca/# instead of http://visualise.ca/. Is there a way to correct this and make sure it is changed to http://visualise.ca/ ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这还不能阻止吗?
Wouldn't this stop it?
我最近碰巧做了很多 ajax 历史。我正在尝试自己的实现,在页面和模态中导航并返回和第四个。取得了很好的进展。
自从测试开始以来,我注意到根哈希;一旦更改回初始页面(一切开始的地方),如果单击“浏览器后退”按钮,则只会丢失哈希值 (#)。如果我将哈希值更改回“”,它将始终在末尾显示/#。
就 IE8 而言,我不相信除了使用 iFrame hack 之外还有任何解决方案,并且由于我还没有时间测试 IE8/iframe hack,所以我无法对此发表评论。
对于我的解决方案,我混合使用了哈希和纯命令控制。我应该在几周内对最终版本进行全面测试(一厢情愿)。
此外,谁在乎 url 末尾是否留下了哈希值/尖锐值。一旦我访问了某个网站,我就不会再查看该 URL;我只是看页面的内容。真的:我突然意识到,只有当我想复制和粘贴时,网址才重要。除此之外,我从不看它。
I happen to be doing a lot of ajax history lately. I am trying my own implementation where I navigate through pages and modals and back and fourth. Making very good progress.
Since the beginning of the tests I have noticed that the root hash; ONCE CHANGED back to the initial page (where it all started) it, only loses the hash (#) if it was a BROWSER BACK button click. If I change the hash back to '', it will ALWAYS show the /# at the end.
As far as IE8 is concerned, I don't believe there is any solution but using the iFrame hack and, since I have not got around to test IE8/iframe hack yet, I cannot comment on it.
For my solution I am using a mix of hash and pure command control. I should have the final version fully tested within a couple of weeks (wishful thinking).
Besides, who cares if a hash/sharp is left at the end of the url. I NEVER LOOK AT THE URL once I hit a web site; I just look at the contents of the page. REALLY: it just hit me that the url is only important when I want to copy and paste it. Other than that, I NEVER look at it.
任何低于 IE9 的内容都会重新加载页面,而不会以 Hash
#
结尾。我的建议是检查 IE 并删除或清空内容。如果您确实想要确切的方式,则必须避开一些 IE 怪癖。Anything less that IE9 will reload the page without the ending Hash
#
. My suggestion is to check for IE and remove or blank out the content. If you do want the exact way, you'll have to dodge some IE Quirks.这适用于 IE。
This will work for IE.