From 8a76ff231b6f8bfe422fa0138fb569e674b2b7e9 Mon Sep 17 00:00:00 2001 From: m1ga Date: Fri, 22 Sep 2023 22:13:13 +0200 Subject: [PATCH] fix 'Empty string passed to getElementById()' --- .../plugins/smoothScroll/enhanceApp.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/vuepress/vuepress-theme-titanium/plugins/smoothScroll/enhanceApp.js b/packages/vuepress/vuepress-theme-titanium/plugins/smoothScroll/enhanceApp.js index daa502d..117be37 100644 --- a/packages/vuepress/vuepress-theme-titanium/plugins/smoothScroll/enhanceApp.js +++ b/packages/vuepress/vuepress-theme-titanium/plugins/smoothScroll/enhanceApp.js @@ -35,9 +35,11 @@ module.exports = ({ Vue, options, router }) => { }) } window.onload = () => { - const element = document.getElementById(location.hash.slice(1)) - if (element) { - element.scrollIntoView() + if (location.hash.slice(1) != "") { + const element = document.getElementById(location.hash.slice(1)) + if (element) { + element.scrollIntoView() + } } } } else { @@ -49,16 +51,20 @@ module.exports = ({ Vue, options, router }) => { if (location.hash) { setTimeout(function() { - const element = document.getElementById(location.hash.slice(1)) - if (element) { - element.scrollIntoView() + if (location.hash.slice(1) != "") { + const element = document.getElementById(location.hash.slice(1)) + if (element) { + element.scrollIntoView() + } } }, 250); } window.onload = () => { - const element = document.getElementById(location.hash.slice(1)) - if (element) { - element.scrollIntoView() + if (location.hash.slice(1) != "") { + const element = document.getElementById(location.hash.slice(1)) + if (element) { + element.scrollIntoView() + } } } }