我必须在页面中向上滚动。因此我在正确的位置放置了一个 anchor ,然后我就这样做了
window.location.href = 'http://example.org/#anchor';
这适用于 FF、Chrome、Safari 和 IE9。但在 IE8 中什么也没有发生(它不滚动)。
我也尝试过:
window.location.hash = "anchor";
window.location.hash = "#anchor";
scrollTo(0, 0);
但是,IE8就是不想滚动。将焦点转移到 anchor 上很重要。无法重新加载。
提前感谢您的任何提示:)
最佳答案
对于 IE 8 只需像这样使用它,它就会工作:
window.location = 'http://example.org/#anchor';
希望这有帮助。
关于javascript - window.location.href 在 IE8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7753909/