Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    New Coder
    Join Date
    Mar 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,703
    Thanks
    0
    Thanked 233 Times in 228 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •