SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2007
    Location
    Toronto
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Return False failing in IE7..?

    Hi everyone,

    I have the following JavaScript code:

    Code:
    function collapsingLink() {
    	
    	myCollapserCollection = document.getElementsByTagName("a");
    	
    	for (var i = 0; i < myCollapserCollection.length; i++)
    	{
    		if (myCollapserCollection[i].className == "folder_collapser")
    			{
    				myCollapserCollection[i].onclick = function() {
    					var myObject = this;
    					var myPattern = /folder/;
    					var myString = this.parentNode.id;
    					var myResult = myString.replace(myPattern, "");
    					
    					var myCurrentLinkList = document.getElementById("links" + myResult);
    					var myCollapseExpandImage = document.getElementById("collapse_expand" + myResult);
    					var myFolderIcon = document.getElementById("folder_icon" + myResult);
    					var myFolderContainer = document.getElementById("folder_container" + myResult);
    					
    					if (myCurrentLinkList.className == "links_show") {
    						myCurrentLinkList.className = "links_hide";
    						myCollapseExpandImage.src = "images/btns/btn_expand.gif";
    						myFolderIcon.src = "images/misc/icon_folder.gif";
    						myFolderContainer.className = "folder_container_hide";
    					}
    					else
    					{
    						myCurrentLinkList.className = "links_show";
    						myCollapseExpandImage.src = "images/btns/btn_collapse.gif";
    						myFolderIcon.src = "images/misc/icon_folder_selected.gif";
    						myFolderContainer.className = "folder_container";
    					}
    					return false;
    				}
    
    			}
    
    	}
    
    }
    You'll notice near the end of the code there is a "return false" statement. That statement is supposed to prevent the link being clicked from navigating to the value in the HREF attribute in HTML. It works fine in Firefox & Opera, but the "return false" has no effect in IE7 and IE6. So, in those browers, the link is followed. I've tried "alerting" messages just before the return false, and it works fine. I've also tried adding "return false" to other spots.

    The strange this is, the code was working fine a week ago in all browsers. No idea why it suddently stopped working. A lot of PHP code has been added though, but I don't see how that could affect it.

    The only solution I have found so far is to completely remove the HREF attribute from the clicked link, but that can't be the only solution. Does IE7 not like the return false in some circumstances?

    Thank you,

    Louis

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2007
    Location
    Toronto
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found the problem. I have another function for opening external windows that is listening for document clicks, and it was overriding the "return false" because it had its own "return true". That seemed to be a mistake anyhow, so I've changed it to return false for both. Seems that IE handles this differently than FF and Opera.

    Fastest ever post-then-solution.

    Louis

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2007
    Location
    Toronto
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correction:

    Adding "return false" on the external window script disabled all links on the page (duh!). So the two options were to remove the "return" completely from the external window script or create an 'else' statement that returned false only for the links in question. The former solution caused JS "warnings" in FF's error console, so we opted for the latter to avoid the warnings.

    Louis


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
  •