Allow anchor links to automatically load JS tabs
See original GitHub issueCurrently it’s necessary to add a small junk of JS (created below) to activate NAV tabs/pills based on the anchor link provided on the tab/pill itself when a page is loaded. This is for deep linking to a tab/pill on a page. This feature request is to integrate this behaviour automatically as part of bootstrap v4 JS.
// Show appropriate pill based on #anchor in URL
var url = window.location.href;
if (url.indexOf("#") > 0){
var activeTab = url.substring(url.indexOf("#") + 1);
$('.nav[role="tablist"] a[href="#'+activeTab+'"]').tab('show');
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:26
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Trying to anchor link to tabs. How to have a link jump to an ...
So, "First uncheck all tabs and then check the only tab that I pressed". It is what the code says.
Read more >Put anchor in tab and click link to switch to each tab
I'd like to ask if there is a way(css or code) to put an anchor in tab content ... I click on a...
Read more >Accessible toggle tabs and accordions - Go Make Things
Start with simple anchor links and content sections with IDs. ... on the browser will now automatically jump you between tabs or accordions, ......
Read more >Anchor link inside same tab - JavaScript - SitePoint Forums
All you need is to add a tablink class to any link that is inside a tab (links that open in the same...
Read more >How to Use HTML to Open a Link in a New Tab - freeCodeCamp
To create a link on a web page, you need to wrap an element (text, a picture, and so on) in an anchor...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here is a code that handles a) changing the url on tab click and b) switching to it:
Indeed it would be great if it was a default and/or switchable feature (via Sass variables).
You can obtain the url anchor directly with
window.location.hash