Print
09
July
2008

window.close in Firefox

The close() function won’t always work in Firefox.

Firefox will only allow you to close a window with the close() function, if it was a script that opened the window in the first place.

Therefore to get around this, we can trick the browser into thinking a script opened the window.

The header script can be defined as follows:

 

<script language="javascript" type="text/javascript">

function closeWindow() {

window.open('','_parent','');

window.close();

}

</script>

 

This opens a non-existent new page, into a target(_parent) frame/window, (which is the window in which the script is executed, so replacing itself). The browser now thinks a script opened a page, and we can close it in the standard way.

 
<a href="javascript:closeWindow();">Close Window</a>

Interested in building next-gen Big Data architecture? Join our webcast on 5/24 at 9am PT. Register here: http://t.co/k5Dsfskg

Oracle Oracle

#Oracle User Groups: Are You a Member Yet? Learn more about our 870 User Groups worldwide and become a member today: http://t.co/LsktPjH5

Oracle Oracle