views:

164

answers:

4

I wrote some code that modifies the images on a webpage. Works with firefox and safari. But tryingto get it to work with Internet explorer has got me stumped. What is the equivalent of "parentNode" in explorer? Or how does one trick it into working?

images = document.getElementsByTagName('img')
parms = {};

for (a=0;a < images.length;a++){
    parent = images[a].parentNode; // <-- What to substitute for explorer?
    parms[a] = {};
    parms[a].bigsrc=parent.getAttribute("href");
    parms[a].w_o = images[a].width;
    parms[a].h_o = images[a].height;
    parms[a].IsBig = false;
    parms[a].loaded = false;
    images[a].border=0;
    parent.setAttribute("href","javascript:MakeBig('"+a+"')");
}
A: 

Hi,

see this link for a possible cause and explanation. (see bloggers conclusion)

Hope this help....

VoodooChild
A: 

Are you expecting the parentNode to be an anchor? It looks like you're trying to just wrap the image in a link. If that's correct, what might work as an alternative is adding an onclick to the image itself, and setting a hand cursor. That could create the appearance of the image being a link without you having to care what the parentNode is.

Rob Cooney
I'm not sure what you mean by "anchor". I'm just trying to change the link that gets pointed to when the image is clicked.
Matthias Wandel
Anchor is the tag used to create a link - that's why when you're making a link in HTML, the tag is 'a.'So rather than trying to use Javascript to modify the anchor tag that surrounds the image, why not instead modify the image's own onclick? Again, that will allow you to avoid having to care what the parentNode is
Rob Cooney
+1  A: 

parentNode works fine in IE (except in certain cases, very likely irrelevant here). The error is almost certainly elsewhere in your code.

Tim Down
Except that explorer fails on the "parentNode" statement, so the rest of the code doesn't even get to run.
Matthias Wandel
At the risk of repeating myself, **`parentNode` is supported and works correctly in IE**. The problem is elsewhere. If you provide some HTML we might be able to tell you where.
Tim Down
Tim is correct that the problem is elsewhere. See my latest answer for where I think it is.
Rob Cooney
Downvoter: please explain yourself.
Tim Down
+1  A: 

The problem is with the assignment of the parentNode to a var called "parent." This seems to be a reserved word in IE that breaks the code. Change the var name and it should work.

Rob Cooney
Thanks. That fixed it. If only IE had given me a useful error message to that effect.
Matthias Wandel
`parent` is **not** a reserved word. Had you used `var parent = images[a].parentNode;` it would have been fine. `parent` is a host object that provides a reference to the window object's parent frame and is apparently (and legally) not settable in IE, and `parent = images[a].parentNode;` attempts to set it.
Tim Down