Window.location.hash 需要语法帮助

发布于 2024-12-01 05:47:22 字数 800 浏览 0 评论 0原文

我的网站位于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

时光暖心i 2024-12-08 05:47:22

这还不能阻止吗?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
    $(document).ready(function() {    
    $(".testPhoto").click(function(event){
        event.stopPropagation();
        alert("do something");
        return false;
    });  
});
</script>
<a class="testPhoto" href="#testPhoto" onclick="testPhoto">Test Photo</a>

Wouldn't this stop it?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
    $(document).ready(function() {    
    $(".testPhoto").click(function(event){
        event.stopPropagation();
        alert("do something");
        return false;
    });  
});
</script>
<a class="testPhoto" href="#testPhoto" onclick="testPhoto">Test Photo</a>
挽清梦 2024-12-08 05:47:22

我最近碰巧做了很多 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.

您的好友蓝忘机已上羡 2024-12-08 05:47:22

任何低于 IE9 的内容都会重新加载页面,而不会以 Hash# 结尾。我的建议是检查 IE 并删除或清空内容。如果您确实想要确切的方式,则必须避开一些 IE 怪癖。

 if ( jQuery.browser.msie && ( parseInt( jQuery.browser.version ) < 9 ) ) {
     window.location = 'http://visualise.ca";
     document.execCommand( 'stop' );
 }

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.

 if ( jQuery.browser.msie && ( parseInt( jQuery.browser.version ) < 9 ) ) {
     window.location = 'http://visualise.ca";
     document.execCommand( 'stop' );
 }
落叶缤纷 2024-12-08 05:47:22
window.location = window.location.href.replace( /#.*/, "");

这适用于 IE。

window.location = window.location.href.replace( /#.*/, "");

This will work for IE.

如此安好 2024-12-08 05:47:22
$('#close').click(function(){

window.location = "http://visualise.ca/";

});
$('#close').click(function(){

window.location = "http://visualise.ca/";

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文