[thelist] js popup images

Karen J. Bowen karen at miinx.com.au
Mon Apr 22 11:27:00 CDT 2002


Adam wrote:
> this script allows me to set the window dimensions according to the picture
> size as I include them- so I need to keep this. I think it's the (url) bit
> thats tripping up the script....
>
> any thoughts?

A few probs:

Firstly, (not a problem, just a comment) you don't need to declare your
newWindow variable as an Object - especially when you then immediately
reset it to be null.  I'd replace both these lines with "var newWindow =
null".

Secondly, you're using the window.open method with the image URL as the
first parameter, which is redundant because you're overwriting the
window contents anyway with the ensuing doc.write statement.  In this
situation, you can just pass an empty string for the URL in the first
win.open statement:
    newWindow = window.open('', 'newWin', 'width=...')

Thirdly, your doc.write statement is only being assigned to the
newWindow variable - nothing is actually being done with it, and in
fact, you're overwriting the window object variable with the doc.write
string - which means you won't be able to refer to the window by that
name later.

To write to the new window, use the syntax:
   newWindow.document.write(docWriteString)

So - assign your string to be fed to the doc.write statement to a new
variable.  Then use the syntax above to write to the new window.
Something like:

var sHtml = '<html><head><title>Larger Image</title>...etc'
newWindow.document.write(sHtml)

(notice too in the above string I've removed a lot of redundant quotes -
you're not inserting any variables in the first bit so just concatenate
all those little strings together, as I have above)

Now, all that being said, I actually don't think you need to use
document.write at all!  You're only using this method to place the image
into the new window - and it should actually be placed perfectly with
the initial window.open() statement alone (including the url this time!)

I hope that helps somewhat.  Good luck with it!

Cheers,
Karen------------
Miinx Design & Development
e :: karen at miinx.com.au
p :: 03 9534 2659
w :: www.miinx.com.au




More information about the thelist mailing list