Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE Always Reloads Entire Page when <a href="#" /> is Clicked

I'm having a weird error with Internet Explorer (Currently version 8, but had the same issue with 7). When clicking a link such as:

<a href="#">Hello</a> 

the page is completely reloaded no matter what.

However a link such as this:

<a>Hello</a>

will work correctly and not reload the entire page.

Is there some sort of setting in IE that can cause this functionality to change?

Info: I have already set security settings to low, and have disabled all addons plus the 'Enable third party addons' option.

Any suggestions are helpful, thanks.

EDIT: Here is what I'm testing

<a href="#" id="btnAddStuff" runat="server" onclick="displayAddStuff();" style="cursor:pointer;">
                <asp:Literal ID="litAddStuff" runat="server" Text="Add Stuff"  /></a>

EDIT #2: I have tested this with multiple versions of IE. With a clean install it works correctly. However testing on a random user's machine with different settings causes the issue.

EDIT #3: Thanks for the replies on how to make this code better. While I appreciate that, my question is if anyone knows if there are configurable settings in Internet Explorer that can cause the browser to run the above code differently?

like image 294
user1048281 Avatar asked Oct 08 '22 21:10

user1048281


1 Answers

If you know a little javasript and or jQuery, you could do this:

$("a[rel='prevDefault']").on('click', function(event){
    if($(this).attr("href").indexOf("#") > -1){
        event.preventDefault();
    }
});

or:

var anchorArray = document.getElementsByTagName("a"), I;
for(I=0;I<anchorArray.length;I++){
   anchorArray[I].click =  function(event){
      if(anchorArray[I].href.indexOf("#") > -1){
          event.preventDefault();
      }
   }
}
like image 113
Eric Hodonsky Avatar answered Oct 12 '22 11:10

Eric Hodonsky