Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: JavaScript
Expertise: Beginner
Oct 18, 2005

Closing a Popup Window Automatically

The following code will close a popup window after the user selects to download the file, or if he/she cancels the download.

Between the <head></head> tags of the document is popped up, add the code below:


<script language="JavaScript">
	function checkVar()	{
		if(document.frm.winFocus.value==1)	{
			window.close();
		}
	}
	
	function changeVar()	{
		document.frm.winFocus.value=1;
	}
</script>
In the <body> tag add this:

<body onFocus="checkVar();">
Somewhere in the body of the document add:

<form name="frm">
	<input type="hidden" name="winFocus" value="0">
</form>
And finally wherever you need them, the links:

<p class="normal">Download ?
	<a href="fileToDownload.zip" onClick="changeVar();" class="zipLink">Yes</a>  
	<a href="javascript:;" onClick="window.close();" class="zipLink">No</a></p>

Note: This works for both Internet Explorer and FireFox.

Konstantinos Lagos
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap