Sunday, May 19, 2024
43
rated 0 times [  49] [ 6]  / answers: 1 / hits: 25278  / 15 Years ago, thu, july 23, 2009, 12:00:00

On this map:



http://web.pacific.edu/documents/marketing/campus-map/version%202/stockton-campus-2.0.htm



I have an anchor at the top, and I want the page to jump to the anchor when a link is clicked.



I'm currently using



window.location = '#top';


It works as expected in FF, Opera, and Chrome, but not in IE 7.



I've tried all permutations like window.location.hash and window.location.assign() and also scrollIntoView(true) and focus().



How can I make it work in IE?



Edit: Nothing seems to work, which makes me think it's not the syntax, but something about the JS... here is the click event handler... could it be because it returns false? I'm grasping at straws.



// Click handler for each location link
$('#index a').click(function()
{
hideMarkers();
location.href = location.href + #top;
var marker = showMarker( $(this).attr('data-id') );
GEvent.trigger( marker, click );
return false;
});


Edit: Assignment to window.location.hash breaks in IE7 and IE8 on pages that were loaded as a result of page redirection via the HTTP Location header. The solution is to return a page with Javascript that itself will perform the redirection. See the answer by Joe Lapp.


More From » internet-explorer

 Answers
26

I have this code in production and it works fine in IE7...



location.hash = #top;


However, if you are just trying to scroll to the top, this ought to be a lot easier...



window.scrollTo(0, 0);

[#99067] Sunday, July 19, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eastonb

Total Points: 498
Total Questions: 91
Total Answers: 102

Location: Tanzania
Member since Wed, Feb 24, 2021
3 Years ago
eastonb questions
Sun, Nov 28, 21, 00:00, 3 Years ago
Tue, Aug 4, 20, 00:00, 4 Years ago
Fri, Apr 24, 20, 00:00, 4 Years ago
Wed, Aug 28, 19, 00:00, 5 Years ago
;