Twenty Twenty-One: Check if anchor exists before triggering in-page navigation.

This prevents JavaScript errors when using hash in URLs without matching them to any existing anchor in the page.

Props rixeo, sabernhardt, pbearne.
Fixes #53619.


git-svn-id: https://develop.svn.wordpress.org/trunk@52213 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras 2021-11-19 13:01:23 +00:00
parent c08e51cc88
commit 48fe42e9d2

View File

@ -180,7 +180,9 @@ function twentytwentyoneExpandSubMenu( el ) { // jshint ignore:line
// Wait 550 and scroll to the anchor.
setTimeout(function () {
var anchor = document.getElementById(event.target.hash.slice(1));
anchor.scrollIntoView();
if ( anchor ) {
anchor.scrollIntoView();
}
}, 550);
}
} );