...

View Full Version : Javascript Pop-up Close()



Racer
03-15-2005, 08:40 PM
Hi,

Here is my code:


<a href=# onClick="window.open('4.jpg','mypicture','width=600, height=450';"> onClick="window.close();"<img src="4.gif"></a>

It works as in it opens in a new window... But I want it when I click on it (After it is open) it closes.

I have 38 of these, so would really not want to have a 10 line code each.

Thanks!

martijntje
03-15-2005, 11:04 PM
You can only have one onclick event. Setting a second one won't work, it will just be ignored, or override the other function.

You will have to use global variables for this, declared in the head of the document, or in an external file, to keep track of the opened windows.

coothead
03-15-2005, 11:33 PM
Hi there Racer,

try it like this...

script

<script type="text/javascript">
<!--
var mywindow;
function openAndShut(url,w,h) {
if(mywindow) {
mywindow.close();
mywindow="";
return;
}
mywindow=window.open(url,'mypicture','width='+w+', height='+h+',left=200,top=0');
}
//-->
</script>
link

<a href="javascript:void(openAndShut('4.jpg',600,450))">
<img src="4.gif" alt=""/>
</a>

coothead



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum