SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Pop-up script

  1. #1
    SitePoint Addict
    Join Date
    Dec 2001
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pop-up script

    I was curious if there is an easier way to make multiple pop-up windows without having such a long code as this:

    <script type="text/javascript">
    function openwindow2()
    {
    window.open("april.jpg","my_new_window","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=500,height=390,border=0")
    }
    </script>
    <script type="text/javascript">
    function openwindow3()
    {
    window.open("may.jpg","my_new_window","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=500,height=390,border=0")
    }
    </script>

    Here I am calling bigger pictures but it gets to be a pain when you have 30 or 40 images. Is there an easier way to do this in javascript or php? Any help would be great! Thanks.

  2. #2
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, what you need to do is to make the function take in extra parameters (in this case, image file name). Something like:
    Code:
    function openWindow( imgName) {
      window.open( imgName, 'myNewWindow', 'width=500,height=390');
    }
    Then in your links you can do something like:
    Code:
    <a href="javascript:openWindow('may.jpg');">See May Pic</a>
    <br>
    <a href="javascript:openWindow('april.jpg');">See April Pic</a>
    Cheers~


Bookmarks

Posting Permissions

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