Skip to content

Commit b894f22

Browse files
authored
Decode target ID from location.hash rather than using it as an ID selector (#646)
1 parent 9c70501 commit b894f22

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

js/menu.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,10 @@ Menu.prototype.documentKeydown = function (e) {
326326
} else if ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9].includes(parseInt(e.key))) {
327327
this.selectPin((e.keyCode - 9) % 10);
328328
} else if (e.key === '`') {
329-
if (document.location.hash) {
330-
document.querySelector(document.location.hash).scrollIntoView(true);
331-
}
329+
const hash = document.location.hash;
330+
const id = decodeURIComponent(hash.slice(1));
331+
const target = document.getElementById(id);
332+
target?.scrollIntoView(true);
332333
}
333334
};
334335

test/baselines/generated-reference/assets-inline.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,10 @@
410410
} else if ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9].includes(parseInt(e.key))) {
411411
this.selectPin((e.keyCode - 9) % 10);
412412
} else if (e.key === '`') {
413-
if (document.location.hash) {
414-
document.querySelector(document.location.hash).scrollIntoView(true);
415-
}
413+
const hash = document.location.hash;
414+
const id = decodeURIComponent(hash.slice(1));
415+
const target = document.getElementById(id);
416+
target?.scrollIntoView(true);
416417
}
417418
};
418419

0 commit comments

Comments
 (0)