Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to a specify tabs\nav #113

Open
verliber opened this issue Apr 27, 2020 · 2 comments
Open

Link to a specify tabs\nav #113

verliber opened this issue Apr 27, 2020 · 2 comments

Comments

@verliber
Copy link

There is a problem with specifying a specific tab in the link. When you open https://domain.com/page/#tab-bar, the first tab shows, instead of the one specified in the hash.

For example link to page https://www.lotar.altervista.org/wiki/wiki/plugin/bootswrapper/nav#tab-bar right away goes to anchor "tab-bar", but when page is fully loaded, automatically opened first tab.

Can script check the hash after the page loads and open a specified tab?

@gareth-johnstone
Copy link

Hi - I've literally just had to do this, thought id browse to see if anyone else had done it ('coz am lazy like that)

Put this in your footer (it's not pretty, but it works):

<script defer>
	document.addEventListener("DOMContentLoaded", function (event) {
		setTimeout(function () {
			/* Set the active tab if hash in URL bar*/
			if (window.location.hash.indexOf('#tab') === 0) {
				document.querySelectorAll("a[href='" + window.location.hash + "'")[0].click();
			}
		}, 500);
	});
</script>

@verliber
Copy link
Author

Thx for code, but i dont understand for what you add if (window.location.hash.indexOf('#tab') === 0) cause on page i doesnt see any #tab id
maybe that will work better:

document.addEventListener("DOMContentLoaded", function (event) {
	setTimeout(function () {
		/* Check for valid hash in URL */
		if (window.location.hash) {
			/* Drop all GET parameters and use only hash*/
			document.querySelectorAll("a[href='" + window.location.hash.split('?')[0] + "'")[0].click();
		}
	}, 500);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants