Simple javascript question about a new window...

Sharky Forums


Results 1 to 4 of 4

Thread: Simple javascript question about a new window...

  1. #1
    Tiger Shark Ark86's Avatar
    Join Date
    Aug 2001
    Location
    Ohio
    Posts
    924

    Simple javascript question about a new window...

    OK, here is my code to open a new window and dynamically write some text to it (it is supposed to be just an image). I just can't figure out how to have the first picture dissappear after I click on another link to another picture without closing the new window. I want it to appear in the same window, but it just adds the picture below the last one. I know why it is doing it, but I don't know how to fix it. Thanks.

    Here is my code:

    function newPicWindow(imageURL, title) {
    picWindow=window.open("", "picWindow", "height=650, width=640, resizable=no, menubar=no, toolbar=no, screenX=100, screenY=100");
    picWindow.document.write("<html><head><title>"+title+"</title></head><body>");
    picWindow.document.write("<img src="+imageURL+"><br>");
    picWindow.document.write("</body></html>");
    }
    My Webpage: http://www.andyknotts.com (Give me feedback)

    My specs:
    ----------------
    AMD Athlon XP 2500+ OC'd to 2100MHz
    Abit NF7 @ 205 MHz FSB
    1.5Gigs PC3200 RAM @410Mhz
    Turtle Beach Santa Cruz
    Altec Lansing 641's
    128meg NVidia 6600GT AGP
    7200rpm 120G w/ WinXP pro
    5400rpm 40G w/ Gentoo Linux
    NEC DVD/RW
    Lite-on 40x12x48 CDRW
    19" Hyundai L90D+ LCD (amazing )

  2. #2
    Reef Shark
    Join Date
    Apr 2001
    Location
    Traverse City, MI, USA
    Posts
    305
    Well what you need to do is give the <img> tag a name so you can reference it, like <img src="myImage.jpg" name="image1">.

    After its written you can change the name with code something like this

    picWindow.document.image1.src="myOtherImage.jpg"

    Thats probably not exact, and I am shooting from the hip here since its been awhile since I coded dynamic images. But that should get you on the right track.
    --------------------
    When you were born you cried and the world smiled. Live your life so that when you die you smile and the world cries.

  3. #3
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    Why even bother putting html tags around the image at all? Why not just have the src of the image used directly in the window.open function?

  4. #4
    Tiger Shark Ark86's Avatar
    Join Date
    Aug 2001
    Location
    Ohio
    Posts
    924
    OK, thanks. Now I do remember about that Begby. But *duh* as grizzly mentioned it would be so much easier to state it directly in the window.open function. Here is my new code:

    function newPicWindow(imageURL) {
    picWindow=window.open(imageURL, "picWindow", "height=650, width=640, resizable=no, menubar=no, toolbar=no, screenX=100, screenY=100");
    picWindow.focus();
    }

    I can't put a title on the page now, but that was unnecessary anyways. Thanks again.
    My Webpage: http://www.andyknotts.com (Give me feedback)

    My specs:
    ----------------
    AMD Athlon XP 2500+ OC'd to 2100MHz
    Abit NF7 @ 205 MHz FSB
    1.5Gigs PC3200 RAM @410Mhz
    Turtle Beach Santa Cruz
    Altec Lansing 641's
    128meg NVidia 6600GT AGP
    7200rpm 120G w/ WinXP pro
    5400rpm 40G w/ Gentoo Linux
    NEC DVD/RW
    Lite-on 40x12x48 CDRW
    19" Hyundai L90D+ LCD (amazing )

Posting Permissions

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