Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-15-2005, 07:40 PM   PM User | #1
Racer
New to the CF scene

 
Join Date: Mar 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Racer is an unknown quantity at this point
Javascript Pop-up Close()

Hi,

Here is my code:

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!
Racer is offline   Reply With Quote
Old 03-15-2005, 10:04 PM   PM User | #2
martijntje
New Coder

 
Join Date: Mar 2005
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
martijntje is an unknown quantity at this point
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.
martijntje is offline   Reply With Quote
Old 03-15-2005, 10:33 PM   PM User | #3
coothead
Senior Coder

 
coothead's Avatar
 
Join Date: Jan 2004
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 1,551
Thanks: 0
Thanked 195 Times in 191 Posts
coothead will become famous soon enough
Hi there Racer,

try it like this...

script
Code:
<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
Code:
<a href="javascript:void(openAndShut('4.jpg',600,450))">
<img src="4.gif" alt=""/>
</a>
coothead
coothead is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:38 AM.


Advertisement
Log in to turn off these ads.