开发者

window.location.href does not work in IE8

开发者 https://www.devze.com 2023-04-12 23:07 出处:网络
I have to scroll up in a page. Therefore I put a an anchor at the corr开发者_如何转开发ect place and then I did

I have to scroll up in a page. Therefore I put a an anchor at the corr开发者_如何转开发ect place and then I did

window.location.href = 'http://example.org/#anchor';

This works fine with FF, Chrome, Safari and IE9. But in IE8 nothing happens (it does not scroll).

I also tried:

window.location.hash = "anchor";
window.location.hash = "#anchor";
scrollTo(0, 0);

However, IE8 just does not want to scroll. It is important that we move the focus to the anchor. A reloading is not possible.

Thanks in advance for any tipps :)


For IE 8 just use it like this, it will work:

window.location = 'http://example.org/#anchor';

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号