-
-
Save nocodesupplyco/9340dfc306b0df77f982c9c50a8b0a1f to your computer and use it in GitHub Desktop.
Set URL From Tab Change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
function doChangeTab() { | |
var tabName = window.location.hash.substr(1); | |
var $tabTrigger = $('[data-tab-name="' + tabName + '"]'); | |
if ($tabTrigger.length) { | |
$tabTrigger.click(); | |
} | |
} | |
//when page is first loaded | |
if (window.location.hash) { | |
doChangeTab(); | |
} | |
//internal page linking | |
$(window).on("hashchange", doChangeTab); | |
$("[data-w-tab]").on("click", function () { | |
history.pushState({}, "", "#" + $(this).data("tabName")); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment