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

Linking To Location On Page - Slow Loading Affects Location

本文关键字:位置 加载 影响 缓慢 链接      更新时间:2023-09-26

我正在尝试链接到页面上的特定位置,但IE似乎加载速度较慢,这破坏了我的位置。
所以在我的导航中,我有一个类似http://mySite/myPage#myLocation的链接我第一次访问该链接时,在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;
    }
}