1

I am trying to get the page to reload with the #hash value, so that on page refresh it takes the hash value and spits out a function. This works in all browsers except for all versions of IE. When I click on the link, it adds the #value, but then after the reload it says #undefined.

Any idea what could be causing this?

Note:

  1. I need the page to reload
  2. It does not need to go to where the hash is, it needs to view the whole page from the top

//refreshes the page when the #by-date-link is clicked $('.sort-trigger').on('click', function(e){ e.preventDefault(); var urlHash = $(this).attr('href'); window.location.hash = urlHash; window.location.reload(); });

Ricardo Alvaro Lohmann
  • 26,031
  • 7
  • 82
  • 82
castorda
  • 11
  • 2

1 Answers1

0

Why the reload? Also, I'm assuming the href attr is #something - that's a hash. Wouldn't it make more sense to dump location.hash and just use onhashchange?

edit: didn't read properly. My guess is the preventDefault in combination with clicking an anchored link is giving IE problems, so maybe store the hash in localstorage (or something similar) and set it onload?

Also found this:

if(event.preventDefault){
    event.preventDefault();
  } else {
    event.returnValue = false;
}

on http://blog.calebnance.com/javascript/how-to-stop-event-actions-from-firing-on-an-element-with-javascript.html

and this: event.preventDefault() function not working in IE

Community
  • 1
  • 1
ravb79
  • 722
  • 5
  • 8
  • This question (http://stackoverflow.com/questions/1000597/event-preventdefault-function-not-working-in-ie) is about Mootools, not jQuery... – Akira Yamamoto Mar 05 '14 at 20:04
  • From the same thread: For all jQuery users out there you can fix an event when needed. Say that you used HTML onclick=".." and get a IE specific event that lacks preventDefault(), just use this code to get it. e = $.event.fix(e); After that e.preventDefault(); works just fine in all browsers including IE. – ravb79 Mar 05 '14 at 20:05