admin管理员组文章数量:1356092
I am using the following code to separate content on a website and it is working fine.
However, if I wanted to link straight to a specific tab from another page how can I go about doing this?
Using the regular way with an ID in the url doesn't seem to work - e.g. mypage.html#a
Thanks in advance
I am using the following code to separate content on a website http://www.bootply./74926 and it is working fine.
However, if I wanted to link straight to a specific tab from another page how can I go about doing this?
Using the regular way with an ID in the url doesn't seem to work - e.g. mypage.html#a
Thanks in advance
Share Improve this question edited Aug 11, 2016 at 22:32 Tom el Safadi 6,8067 gold badges55 silver badges119 bronze badges asked Aug 11, 2016 at 22:18 tinOfBeanstinOfBeans 7371 gold badge9 silver badges22 bronze badges 1- Hey, did it work? If yes could you please accept my answer? – Tom el Safadi Commented Sep 1, 2016 at 18:06
2 Answers
Reset to default 6Although I do not have the chance to try it, I think you can do it via javascript.
When you are ming from another page to ex. mypage#abc
, #abc
can be retrieved by window.location.hash
. So, a simple solution could be this javascript:
$(document).ready(function(){
// get the tab from url
var hash = window.location.hash;
// if a hash is present (when you e to this page)
if (hash !='') {
// show the tab
$('.nav-tabs a[href="' + hash + '"]').tab('show');
}
});
Just make sure that the tabs you need to link (from other pages) have ids same as your hashes
The Advantage with this code is that you can navigate to those tabs from other sites as well not only within the same page.
$('#tab1 a').click(function (e) {
e.preventDefault();
$('a[href="' + $(this).attr('href') + '"]').tab('show');
})
You can see it working in my JSFiddle below:
http://jsfiddle/Anokrize/nP2Zk/317/
本文标签: javascriptLink straight into a specific tabpane from another pageStack Overflow
版权声明:本文标题:javascript - Link straight into a specific tab-pane from another page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744008435a2575118.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论