[removed].hash issue in IE7

后端 未结 4 1908
悲&欢浪女
悲&欢浪女 2020-12-19 09:18

We have a javascript function that should \"move\" a page to a certain position using anchors. This function just does window.location.href = \"#\" + hashName.

4条回答
  •  既然无缘
    2020-12-19 09:27

    I justed tested this in IE7 under Vista, maybe the issue only exsists in IE7 under XP? Because this works fine for me in IE7, Chrome and Firefox:

     window.location.hash = hashName;
    

    If this really doesn't work then we could use scrollIntoView as Kennebec suggests.

     function scrollToAnchor(anchorName){
       //set the hash so people can bookmark
       window.location.hash = anchorName;
       //scroll the anchor into view
       document.getElementsByName(anchorName)[0].scrollIntoView(true);
     }
    

    Use like this:

     
     
     

    I will be scrolled into view

提交回复
热议问题