2012-11-21 53 views
0

我的頁面上有一個Jquery選項卡,我想阻止訪問者從包含URL中的錨的外部鏈接進入頁面(www.mypage.html#myanchor )頁面將跳轉到實際的錨點。我只想要選中標籤,而不是跳轉。 我仍然在jQuery的非常新手,這是我使用的建設的標籤代碼:jquery選項卡,避免錨從外部鏈接跳轉

<script> 

    $(function() { 

$("#tabs").tabs({ 

     select: function(event, ui) { 

      // loading an iframe src on select 
      if (ui.index==2){ 
      go('iframes/tendaggi_ignifughi.html'); 
      } 
     }  

     }); 

}); 

    </script> 

,我應該如何修改上面的代碼來實現我所需要的任何答案是極大的讚賞。

回答

2

試試這個代碼:

if (location.hash) {   // do the test straight away 
    window.scrollTo(0, 0);  // execute it straight away 
    setTimeout(function() { 
     window.scrollTo(0, 0); // run it a bit later also for browser compatibility 
    }, 1); 
}