Results 1 to 3 of 3

Thread: Very strange link behavior in IE6.

  1. #1
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default Very strange link behavior in IE6.

    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:

    Code:
    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!
    Last edited by jlizarraga; 01-21-2009 at 11:13 PM. Reason: resolved

  2. #2
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    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.
    Last edited by jlizarraga; 01-21-2009 at 10:55 PM. Reason: clarify

  3. #3
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •