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

Fix anchor tags are not working in chrome on first load (#243) #256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions assets/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@
return string.replace(/^\s+|\s+$/g, '')
}

/**
* credit: https://stackoverflow.com/a/13348618
*/
function isChrome() {
const isChromium = window.chrome;
const winNav = window.navigator;
const vendorName = winNav.vendor;
const isOpera = typeof window.opr !== "undefined";
const isIEedge = winNav.userAgent.indexOf("Edge") > -1;
const isIOSChrome = winNav.userAgent.match("CriOS");
return (
isIOSChrome ||
(isChromium !== null &&
isChromium !== undefined &&
vendorName === "Google Inc." &&
isOpera === false &&
isIEedge === false)
);
}
/*--------------------------------------------------------------------------*/

var Menu = React.createClass({
Expand Down Expand Up @@ -455,6 +474,13 @@
parent.appendChild(button)
})
}

if (location.hash && isChrome()) {
const hash = document.querySelector(location.hash);
if (hash) {
hash.scrollIntoView();
}
}
}

if (document.readyState == 'loading') {
Expand Down