Forum Moderators: open

Message Too Old, No Replies

Open Image in new window

         

MartinL

8:43 pm on Aug 14, 2009 (gmt 0)

10+ Year Member



I came across this script posted by rocknbil Feb 26, 2009. (I couldn't figure out how to reply to it.)

function openwindow(img,w,h,caption) {
var day = new Date();
var id = day.getTime();
// add some padding for the window
var winwidth=w+25;
var winheight=h+50;
var params =
'status,resizable,width='+winwidth+',height='+winheight;
var msg=
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'
+ ' "http://www.w3.org/TR/html4/loose.dtd">\n'
+ '<html lang="en">\n'
+ '<head><title>'+caption+'<\/title>\n'
+ '<body><img src="'+img+'"width="'+w+'" height="'+h+'" border="0" >\n'
+ '<form style="text-align:center">\n'
+ '<input type="button" onClick="window.close();" value="Close Window">\n'
+ '<\/form>\n'
+ '<\/body>\n'
+ '<\/html>\n';
var win = window.open(img,id,params)
win.document.write(msg);
win.document.close();
return false;
}

It works just fine in FireFox, Opera, and Chrome. But in IE8 (regular or compatibility mode)it hangs at " win.document.write(msg); " with the message Object Required".
Any suggestions as how to fix it?
Many thanks,
MartinL

whoisgregg

9:38 pm on Aug 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, MartinL!

I see a missing semicolon at the end of this line:

var win = window.open(img,id,params)[red];[/red]

Often when I see error line numbers I look right above the line. :)

rocknbil

4:18 pm on Aug 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



^^ Agreed, and welcome aboard MartinL, I searched for and found that thread - I often have typos, but this is not one of them, the original code is correct. :-)

MartinL

4:25 pm on Aug 17, 2009 (gmt 0)

10+ Year Member



Many thanks. My eyes aren't what they used to be. That plus senior moments makes for great coding!