Overlay: Fixed handling of same-page links to elsewhere on the page

Fixes #5767