View Full Version : Resolved Very strange link behavior in IE6.

01-21-2009, 10:36 PM
Hi all,

I am populating a list of links. Each link is just some <span>'s (the first span has an image) and a couple of hidden <input>'s.

I attach an onclick listener to each link, and the callback function is the following:

var oTarget = YAHOO.util.Event.getTarget(e); // In YUI, this returns the clicked node.
if(oTarget.nodeName.toUpperCase() != "A"){
oTarget = YAHOO.util.Dom.getAncestorByTagName(oTarget, "a"); // This one is self explanatory.
var oInputs = oTarget.getElementsByTagName("input");
document.location.href = "details.html?&location=" + oInputs[1].value + "&VIN=" + oInputs[0].value;

For some strange reason, IE6 only changes document.location.href when the original event target was an <img>, even though the original target doesn't impact the final result. If I put alerts for the input values after the last line in that function, the correct values are displayed, it just doesn't want to execute the "document.location.href =" line unless the original target was the <img>.

Only IE6 has this problem, and I've never experienced something like this before. :(

Can anyone shed some light on this? I am as stumped as it gets! :confused:

01-21-2009, 10:40 PM
Also, there are no hasLayout issues going on (that I know of, IE6 Dev toolbar says the links, their children, and their container all haveLayout) - the links are fully clickable and fire the event in IE6 no matter where you click them.

edit: More info: The href value for the links is "javascript:void(0);". I changed document.location.href to window.location.href - same result - only navigates to new page when the original target was in image. Added try/catch, and no error is thrown when setting window.location.href is not successful.

01-21-2009, 11:12 PM
Found the answer while sifting through many a JS pissing contest from Google. (it's amazing how fast good info can be buried by large egos)

I was under the impression that when using "javascript:void(0)" as an href for links, you don't need to return false or otherwise prevent the link's default event from firing.

I don't know if IE6 is behaving badly, or the other browsers are being nice to my broken code, but you definitely can't rely on javascript:void(0) in this way.