Reputation: 161
I have two html files in a prototype. If I open any of them, a closing button does the job.
<img src="img/x-01.png" onclick="window.close()" />
After I navigate to another html, the same code sample stops working. And doesn't work even if I come back to the previous page via browser`s "back" button.
How could that be? I'm new to js, so is there some concept I don't understand?
As the code is scattered among several files, I uploaded a stripped-down app - for observing this behaviour.
Upvotes: 3
Views: 1956
Reputation: 114367
window.close()
can only be called by the same page that opened the window in the first place (otherwise third-party web pages would be closing windows on us at will). Once you navigate away, you lose this connection and ability.
Upvotes: 3