Javascript IE7中的window.location.hash问题

Javascript IE7中的window.location.hash问题,javascript,internet-explorer,internet-explorer-7,Javascript,Internet Explorer,Internet Explorer 7,我们有一个javascript函数,它应该使用锚将页面“移动”到某个位置。此函数只执行window.location.href=“#”+hashName。这在FF中有效,但在IE中无效。我在Windows XP下使用IE7测试了这段代码。 我尝试了使用window.location.href,window.location.hash,window.location.replace以及所有这些方法,但是使用了文档对象。 有人知道如何处理这个问题吗?您是否尝试过只更改位置。哈希值 window.lo

我们有一个javascript函数,它应该使用锚将页面“移动”到某个位置。此函数只执行
window.location.href=“#”+hashName
。这在FF中有效,但在IE中无效。我在Windows XP下使用IE7测试了这段代码。 我尝试了
使用window.location.href
window.location.hash
window.location.replace
以及所有这些方法,但是使用了
文档
对象。
有人知道如何处理这个问题吗?

您是否尝试过只更改
位置。哈希值

window.location.hash = "#" + hashName;

IE和大多数其他浏览器将滚动到带有anchor.focus()的锚点,或滚动到带有element.scrollIntoView(true)id的任何元素。scrollIntoView(true)

我刚刚在Vista下的IE7中测试过这个问题,也许这个问题只存在于XP下的IE7中?因为这对我在IE7、Chrome和Firefox中的工作很好:

 window.location.hash = hashName;
如果这真的不起作用,那么我们可以按照Kennebec的建议使用scrollIntoView

 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);
 }
这样使用:

 <script type='text/javascript'>scrollIToAnchor('foo');</script>
 <a name='foo'></a>
 <p>I will be scrolled into view</p>
scrollitoanch('foo');
我将被滚动到视图中


我也遇到了一个问题


对此不熟悉。不过看起来不错。去测试…你说的“使用文档对象”是什么意思?你应该使用
窗口。位置
如答案-
文档中所建议。位置
是壁虎特有的!我使用了这两种方法——Vladimir不起作用,在IE7/XP中对我起作用。。。