opening new windows - passing attributes to a new window won't work

They have: 6 posts

Joined: Jun 1999

Hello all,
I hope somebody out there can take a minute to help me out with a problem that I don't believe to be that hard.

I have a thumbnail image tag as shown below. OnClick calls the "OpenPicture" function and passes the name of the full size picture.

<A HREF="javascript:void(0)"onClick="OpenPicture('Brides01.jpg')"><IMG SRC="Brides01Thumb.jpg"BORDER=0></A>

Below is the function. I believe this line is where the problem must be. I have tried this line using several different formats with no luck. A new window does open but the image shows as a broken image.

OpenWindow.document.write("<IMG SRC=url>")

function OpenPicture(url){

var OpenWindow=window.open("", "newwin", "height=280,width=280");
OpenWindow.document.write("<HTML>")
OpenWindow.document.write("<TITLE>New Window</TITLE>")
OpenWindow.document.write("<BODY BACKGROUND='outdoorBackground.jpg'>")
OpenWindow.document.write("<IMG SRC=url>")
OpenWindow.document.write("</BODY>")
OpenWindow.document.write("</HTML>")

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

Try writing that line like this:

OpenWindow.document.write("<IMG SRC="+url+">");

The variable needs to be escaped from the quotes, it should work then. Smiling

----------
Page Resource: http://www.pageresource.com
JavaScript City: http://www.javascriptcity.com

They have: 6 posts

Joined: Jun 1999

Thanks for the help, It works fine now.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.