handleScrollRestoration - Add script to head

This will set history.scrollRestoration to "manual" on page start, if hash starts with "link-"
This commit is contained in:
2020-10-26 12:33:40 +05:30
parent 686a3e49e4
commit 4cf46e250e
2 changed files with 14 additions and 0 deletions
+6
View File
@@ -102,4 +102,10 @@ module.exports = {
},
],
],
scripts: [
{
src:
'/scripts/handleScrollRestoration.js',
},
]
};
@@ -0,0 +1,8 @@
var hash = window.location.hash;
var hashName = hash.substring(1, hash.length);
if (hashName.startsWith("link-")) {
if ("scrollRestoration" in history) {
history.scrollRestoration = "manual";
}
}