Only try to scroll to element when the target path exactly matches the base path of the current page

Fixes #121045

For pages that set `<base>`, if the target of link click goes to different path than the current page (taken from `base`), treat it as a normal link open instead
This commit is contained in:
Matt Bierner 2021-04-14 18:03:09 -07:00
parent 0a6309be1e
commit be2026c324
No known key found for this signature in database
GPG key ID: 099C331567E11888

View file

@ -324,8 +324,8 @@ export async function createWebviewManager(host) {
if (node.tagName && node.tagName.toLowerCase() === 'a' && node.href) {
if (node.getAttribute('href') === '#') {
event.view.scrollTo(0, 0);
} else if (node.hash && (node.getAttribute('href') === node.hash || (baseElement && node.href.indexOf(baseElement.href) >= 0))) {
let scrollTarget = event.view.document.getElementById(node.hash.substr(1, node.hash.length - 1));
} else if (node.hash && (node.getAttribute('href') === node.hash || (baseElement && node.href === baseElement.href + node.hash))) {
const scrollTarget = event.view.document.getElementById(node.hash.substr(1, node.hash.length - 1));
if (scrollTarget) {
scrollTarget.scrollIntoView();
}