直接链接到另一个页面

时间:2016-08-11 22:18:23

标签: javascript html twitter-bootstrap-3

我使用以下代码来分隔网站http://www.bootply.com/74926上的内容,但它运行正常。

但是,如果我想直接链接到另一个页面中的特定标签,我该怎样才能这样做?

在网址中使用带有ID的常规方式似乎不起作用 - 例如的mypage.html#一个

提前致谢

1 个答案:

答案 0 :(得分:2)

虽然我没有机会尝试,但我认为你可以通过javascript来实现。

当你从另一个页面进入前。可以mypage#abc检索#abcwindow.location.hash。所以,一个简单的解决方案可能是这个javascript:

$(document).ready(function(){
    // get the tab from url
    var hash = window.location.hash;
    // if a hash is present (when you come to this page)
    if (hash !='') {
        // show the tab
        $('.nav-tabs a[href="' + hash + '"]').tab('show');
    }
});

只需确保您需要链接的标签(来自其他页面)的ID与您的哈希值相同

相关问题