Friday, April 25, 2008

JavaScript Suicide

Getting busy with a day by day working hours makes me for a long time not involved on writing this blog anymore. I do apologize for this.

In some situation, we might want to run a script (asp, php, c#, jsp, cfm) using browser and then after execute the script the browser closed automatically.

You can simply do this using the JavaScript code below. Put this code at the beginning of your script :

function doSuicide()
opener = self;

And then put this code at the end of your script :


How this JavaScript code works?

First, the browser will load all the script till the end of the script. After the browser parsing the code and found the JavaScript function that call doSuicide() function then this will make the browser forced to closed by himself.

This JavaScript code known works on Internet Explorer and Firefox 2+

No comments: