Discussion Locked

Closing first browser window

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
When I load my first ASP.NET application page in the browser, I want to transform the browser window by removing toolbar, menus and status bar. As I can't do that, I open another window without these controls, but then I cannot close the first window without the messagebox which warns the user that the window will be closed. Is there any possibility to close the first window without the messagebox, or to "clean up" the first window while loading ASP.NET page?

1 reply

by ed woychowsky

In the early days of the internet this was one of the practical jokes. Simply coding window.close() in client-side JavaScript was enough. People quickly got upset so future browser releases wouldn’t permit it for the parent window.

I’ll probably be flamed for this but, notice that I said “parent window”, the trick is to make the browser think that the parent window isn’t the parent window.

// Open window here

try {
x = window.opener.location; // Error, if not a child window
window.close();
}
catch(e) {
window.opener = top;
window.close();
}

Hope this helps.

This discussion is closed to new replies.