• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Browser Suicide

You’ve already learned how to close a pop-up window in the “Close Pop-Up Window” tip on the previous page. Did you try it on a parent window—a window that isn’t a pop-up window? If you try that method, you will get a browser security warning. The warning dialog definitely sounds scary to the average website viewer.

So how do you kill the parent window? Ask most anyone and she’ll tell you it can’t be done because it is a security issue. She might suggest an ActiveX control, but many users disallow those. In fact, if this tip doesn’t work for you, it means that the browser makers have gotten wise to this technique and have patched this security hole.

The JavaScript is so darn simple, you might even smack your forehead and say, “Why didn’t I think of this?”. I sure did when I first learned of this code.

function suicide(){
self.opener = self;
self.close();
}

Call the function from an event on the <body> tag or a hyperlink. For example:

<a href="javascript:;" onClick="suicide()">Kill me!</a>

I don’t suspect that this function will work forever in all browsers. They’re bound to catch on sooner or later. In the meantime, enjoy this one and use it to wow your geek friends. Just please don’t use it for evil!

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint