最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - window.location.href does not work in IE8 - Stack Overflow

programmeradmin0浏览0评论

I have to scroll up in a page. Therefore I put a an anchor at the correct place and then I did

window.location.href = '';

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 :)

I have to scroll up in a page. Therefore I put a an anchor at the correct place and then I did

window.location.href = 'http://example/#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 :)

Share Improve this question asked Oct 13, 2011 at 12:10 mknmkn 13.2k17 gold badges52 silver badges64 bronze badges 3
  • 1 Have you tried the ".scrollIntoView()" method on the element? – Pointy Commented Oct 13, 2011 at 12:12
  • @Pointy then I would have to get the anchor element first right? I tried a similar solution with a <div id="anchor"> and then get that element and call scrollIntoView on it. It does not work :( – mkn Commented Oct 13, 2011 at 12:38
  • I've used "scrollIntoView" in IE many times and it has always worked fine for me. Maybe if you could prepare a jsfiddle people could help investigate. – Pointy Commented Oct 13, 2011 at 13:39
Add a ment  | 

1 Answer 1

Reset to default 7

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

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

Hope this helps.

发布评论

评论列表(0)

  1. 暂无评论