Click to See Complete Forum and Search --> : Simple javascript question about a new window...


Ark86
12-18-2002, 11:21 PM
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>");
}

Begby
12-19-2002, 10:24 AM
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.

Grizzly
12-19-2002, 11:51 AM
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?

Ark86
12-19-2002, 02:50 PM
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.