Window.location = #anchor does not work in IE

On this map:

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

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

I am currently using

window.location = '#top';

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

I tried all permutations like window.location.hash and window.location.assign (), as well as scrollIntoView (true) and focus ().

How can I make it work in IE?

Edit: nothing works, which makes me think that this is not syntax, but something about JS ... here is the click event handler ... maybe because it returns false? I grab onto a straw.

// 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;
});

: window.location.hash IE7 IE8 , HTTP "Location". , Javascript, . . .

+3
6

, IE7...

location.hash = "#top";

, , ...

window.scrollTo(0, 0);
+6

location - href

, hash, , .

top.location.hash = 'top';

/href - scrollTo()

top.scrollTo( 0, 0 );
+7

windows.location.hash, , IE7 IE8 ( , Vista). , -.

IE7 IE8, window.location.hash , HTTP "".

StackOverflow (. ). , Javascript. StackOverflow:

<html>
<head>
    <meta http-equiv="refresh" content="0; url=__REDIRECT_LOCATION__">
    <script>window.location = "__REDIRECT_LOCATION__";</script>
</head>
</html>

, , - , , .

, scrollTo(), , - , .

+3

location.href = location.href.split("#")[0] + "#top"

EDIT: .

+2

. ,

window.location = ((location.href).indexOf('#') == -1 ? location.href + "#top" : location.href);

0
window.location.href = '#top';

And if that doesn't work, try the full URL

window.location.href = 'http://domain.com/my.html#top';
-1
source

Source: https://habr.com/ru/post/1713377/


All Articles