2016-02-26 63 views
0

我想鏈接到頁面上的特定位置,但IE似乎加載速度較慢,這是拋出我的位置。
所以在我的導航欄中,我有一個鏈接,如http://mySite/myPage#myLocation 我第一次去那個鏈接,在IE瀏覽器,它不會去正確的位置,因爲圖像仍然加載在頁面上。它會在初始階段觸及它,但隨着其他事物的加載,它會被推下頁面。如果我回到頁面,那很好。如果我清除緩存並再次嘗試,我可以複製該問題。 Chrome和FF工作正常。鏈接到頁面上的位置 - 緩慢加載影響位置

任何想法如何解決這個問題?

回答

0

那麼這裏有一個快速的解決方案,我想出了這個作品。不知道這是否是最好的,但它的工作。 如果在加載過程中位置發生變化,則頁面完全加載後會返回到該位置。

//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; 
    } 
}