View Full Version : ViewImage JavaScript Not Working in IE8

07-19-2009, 10: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:


<!-- 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) {
setTimeout("ViewImage('"+ifile+"',"+ix+","+iy+",'"+ititle+"')", 250);
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>");
// End -->

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

<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!


07-19-2009, 11:16 PM
if(sWidth!=ix || sHeight!=iy) {
setTimeout("ViewImage('"+ifile+"',"+ix+","+iy+",'"+ititle+"')", 250);
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>

07-19-2009, 11:56 PM
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!


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum