Using window.close

I came across a situation where another web application is calling a web application I have.  The calling application is limited to the javascript that can be used to pass information to my application.  So the parameters are passed through a querystring GET.  The resulting web page from my application appear as a new web page tab in IE7.  The desired result is not to have the new window appearing.

I tried to use window.close(); in the body onload event but it prompts the use to confirm the closing.  I found this trick to close the window without confirming: open a blank window in the current window then close it.  Here is some code that shows how it works

<HTML>
<SCRIPT LANGUAGE="JScript">
function closeNoAlert() {
  window.open('','_parent',''); 
  window.close(); 

}
function closeAlert() {
  window.close(); 
}

</SCRIPT>
<BODY >
<input type='button' onclick='closeAlert();' value='Close With Alert'/>
<input type='button' onclick='closeNoAlert();' value='Close Without Alert'/>
</BODY>
</HTML>

Print | posted on Wednesday, May 14, 2008 10:45 AM