From b0dba3ced7e9cc9836ae7fa360add7f08a1ee038 Mon Sep 17 00:00:00 2001 From: Janarthanan Chandrasekaran Date: Mon, 9 May 2022 17:11:17 +0530 Subject: [PATCH] [Fixes #243] Anchor tags are not working in chrome on first load --- assets/js/docs.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/assets/js/docs.js b/assets/js/docs.js index ae899b32..d5cdd6c4 100644 --- a/assets/js/docs.js +++ b/assets/js/docs.js @@ -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({ @@ -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') {