5

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?

user1048281
  • 233
  • 1
  • 4
  • 16
  • Would you mind editing your post to make the links show as code blocks? I can't do it for you as the edit is too small to process. 4 space indents create code blocks. You can check the help panel on the question editor if my explanation is unclear. – John H Jan 26 '12 at 17:32
  • Thanks, it'll increase your chances of getting the answer you need. – John H Jan 26 '12 at 17:48

3 Answers3

2

Please post your code.

I think you are referring to "the JUMP"

Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

What's the effect of adding 'return false' to a click event listener?

I think these threads will be more useful. Marked to delete???

Community
  • 1
  • 1
TheBlackBenzKid
  • 26,324
  • 41
  • 139
  • 209
  • I have tested my code and have it working in multiple browsers. This error is occurring only on one specific user's machine. I should have posted that in the initial question. That is why I believe it has to do with IE settings. – user1048281 Jan 26 '12 at 17:31
2

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();
      }
   }
}
Eric Hodonsky
  • 5,617
  • 4
  • 26
  • 36
  • While I was never able to track down what was causing this one person's IE to cause these issues, I was able to use some similar code given here to remove all of the href="#" attributes so that it would work for them. I am still curious as to how it comes about that one IE install does this and no others will. But either way this solution seemed to work, cheers. – user1048281 Feb 02 '12 at 21:05
  • @user1048281 this comes from different operating systems and different kernels and different update builds even on the same OS can act quite differently depending on what you're up against. IE likes to think more for the user and programmer and has draw backs that you have to write acceptances for. – Eric Hodonsky Feb 02 '12 at 22:11
0

Do you have the base element set up in the head? This is a standard cause of that.

Using JavaScript can help you get past that. Something along the lines of:

<a href="javascript:;" onclick="document.location.hash='#' />Hello</a>

Should take care of it. Or you could have it return false too. Depending on what you're looking to do.

Tango Bravo
  • 3,221
  • 3
  • 22
  • 44