0

我正在使用Ben Almon 的 Hash history 插件,一切正常,除了使用返回按钮返回主页时 - 它没有哈希标签。

所以我要使用后退按钮从:www.mysite.com/#category1 到 www.mysite.com/。

尽管浏览器发生了变化,但我的页面并没有重新加载。

我的代码与他的示例代码几乎相同。虽然,如果 URL 中没有哈希标记,我只想准确加载浏览器 URL 中的内容。目前它什么也不做。

哪来的???'s 在我下面的代码中,我尝试输入一行以将 URL 重定向到我的主页,但它一直在无限循环中触发,因为插件读取没有#tag,所以再次重新加载页面。

所以问题是,应该在 ??? 以下:

        $(document).ready(function() 
    {
       // Bind an event to window.onhashchange that, when the hash changes, gets the
      // hash and adds the class "selected" to any matching nav link.

      $(window).hashchange( function(){
        var hash = location.hash;
        var param=  ( hash.replace( /^#/, '' ) || 'Blank' );

    if(param=='Blank'){ **?????**}

     else
     {
      // Set the page title based on the hash.
      document.title = ( param );

     //do other stuff 
     }
     });

      // Since the event is only triggered when the hash changes, we need to trigger
      // the event now, to handle the hash the page may have loaded with.

          $(window).hashchange();


});
4

0 回答 0