Overlay: Fixed bug that prevented in certain scenarios an overlay being opened through JS a second time

Fixes #6102