链接到页面上的位置 - 加载缓慢会影响位置

Linking To Location On Page - Slow Loading Affects Location

我正在尝试 link 到页面上的特定位置,但 IE 加载速度似乎较慢,这导致我的位置偏离。
所以在我的导航中我有一个 link 像 http://mySite/myPage#myLocation 我第一次去那个 link,在 IE 中,它没有去正确的位置,因为图像仍在页面上加载。它最初会点击它,但随着其他内容的加载,它会被推下页面。如果我回到页面,那很好。如果我清除缓存并重试,我可以重现问题。 Chrome 和 FF 工作正常。

有什么办法解决这个问题吗?

好吧,这是我想出的一个快速解决方案。不确定这是否是最好的,但它正在工作。 如果位置在加载过程中移动,它会在页面完全加载后返回到该位置。

//Get the location ID if it exists in the URL, strip off #
var pageLocation = window.location.hash.split('#')[1];

//After page fully loaded, redirect to that location
//Prevents location from getting pushed away during IE slow page load
if (typeof pageLocation != "undefined") {
    window.onload = function () {
        location.hash = pageLocation;
    }
}