...

View Full Version : ViewImage JavaScript Not Working in IE8



Scout720
07-19-2009, 11:55 PM
The ViewImage JavaScript is an important part of my web site. I use it to display larger images of products, difinitions of features and finish sample photos. These images are different sizes. The size of the window is specified in the link to the image. The window remains open until the user closes it. It has fuctioned properly in all earlier IE versions.

With IE8 the window opens at the correct size, but does not load the image, and then immediately re-closes, then opens again and this continues in a flashing sequence! The only way to stop it is to back out of the page.

This is the part of the Script posted in the Header:
[CODE]


<SCRIPT LANGUAGE="JavaScript">


<!-- Begin
function ViewImage(ifile,ix,iy,ititle) {
var win;
var sWidth;
var sHeight;
var NS = (document.layers) ? 1 : 0;
win = window.open("","imageviewer","width="+ix+",height="+iy+",menubar=no,toolbar=no");
if (NS) {
sWidth = win.innerWidth;
sHeight = win.innerHeight;
} else {
sWidth = win.document.body.clientWidth;
sHeight = win.document.body.clientHeight;
}
if(sWidth!=ix || sHeight!=iy) {
win.close();
setTimeout("ViewImage('"+ifile+"',"+ix+","+iy+",'"+ititle+"')", 250);
return;
}
win.document.open();
win.document.write("<html><head><title>"+ititle+"</title>");
win.document.write("</head><body>");
win.document.write('<div style="position:absolute;width:'+ix+'px;height:'+iy+'px;left:0px;top:0px">');
win.document.write("<img src="+ifile+"></div></body></html>");
win.document.close();
}
// End -->
</script>

This is an example of the link code that activates it and is posted in the body of the page:
[CODE]

<a href="javascript:ViewImage('../cat/20530.jpg',456,351,'20530 Product')"><img src="../images/20530p.jpg" alt="20530 Product"></a>

Any help to make this code workable in IE8 would greatly be appreciated. I am at my wits end!:eek:

Thanks a bunch!

Scout720

randomuser773
07-20-2009, 12:16 AM
if(sWidth!=ix || sHeight!=iy) {
win.close();
setTimeout("ViewImage('"+ifile+"',"+ix+","+iy+",'"+ititle+"')", 250);
return;
}
This code is causing the closure and reopening of the window if its reported dimensions don't match those specified. This would probably happen under a strict doctype, but I don't see the rationale and I would remove it.

Also the links should be constructed like this:


<a href='../cat/20530.jpg' onclick="ViewImage('../cat/20530.jpg',456,351,'20530 Product');return false"><img src="../images/20530p.jpg" alt="20530 Product"></a>

Scout720
07-20-2009, 12:56 AM
Removing that part of the code seems to have done the trick! Even the old links work without the suggested changes which is great for me! There are thousands of them in the database which would need to be modified.

Thank you so much for responding to my call for help! What a relief!

I really appreciate it!

Scout720



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum