SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with on the fly documents

    Hello! I need help. I'm still learning javascript and stuck. I have a script to click on a thumnail and have the larger image open in a new window with some text. Here's the script I'm using:

    function image1() {
    myWin= open("", "displayWindow", "width=300,height=450,status=no,toolbar=no,menubar=no");
    myWin.document.open();

    myWin.document.write("<html><body bgcolor=black><img src=1_300x388.jpg><br>");

    myWin.document.write("<font size=4><font color=white>");

    myWin.document.write("This is image 1 ");

    myWin.document.write("</font></body></html>");

    myWin.document.close();
    }


    The problem is, I have about 30 thumbnails. Do I need to rewrite this function for each thumnail? the only thing that will change is the image src in the new window and the text (this is image 1, this is image 2, etc) written to the new window.

    I know theres a simpler solution but cant find it. thanks in advance for anyone's help.
    "hee hee"

  2. #2
    SitePoint Zealot Atirez's Avatar
    Join Date
    Nov 2000
    Location
    England
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    the easiest way to do this would be to declare the function in the head of your document and pass parameters to the function containing any information that you wish to change on the new document. Like:

    Code:
    function newImageWindow(imageSrc)
    {
        .....
        myWin.document.write("<html><body bgcolor=black><img src='" + imageSrc + "'><br>"); 
        .....
    All you have to do then is to use the variable in place of the constant as shown above. Just then call the function where ever you need to and pass different image src's to it like so:

    Code:
    onMouseDown="newImageWindow('anotherImage.jpg')"
    Hope this helps,
    Atirez

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks I'll try that.
    "hee hee"


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
  •