[removed] = #anchor doesn't work in IE

前端 未结 6 535
南笙
南笙 2020-12-10 09:24

On this map:

http://web.pacific.edu/documents/marketing/campus-map/version%202/stockton-campus-2.0.htm

I have an anchor at the top, and I want the page to ju

6条回答
  •  [愿得一人]
    2020-12-10 09:55

    I also had a problem with windows.location.hash working in all browsers but IE7 and IE8 (at least on Vista). After much experimenting, I discovered that page redirection was breaking hash assignment.

    An error will occur in IE7 or IE8 if you assign a value to windows.location.hash from within a page that was loaded as a result of redirection via the HTTP "Location" header.

    After discovering this, I was able to find a fix elsewhere on StackOverflow (see here). The solution is to have the browser redirect via Javascript. Here I repost the solution from the other StackOverflow page:

    
    
        
        
    
    
    

    This would explain why some people were having a problem with setting hash and some were not, but I do not know that the originator of the thread was redirecting.

    I should also point out that I couldn't just use scrollTo() because my purpose was to remove the hash tag from the address bar without reloading the page, not to scroll.

提交回复
热议问题