在这张地图上:
http://web.pacific.edu/documents/marketing/campus-map/version%202/stockton-campus-2.0.htm
我在顶部有一个锚点,我希望页面在单击链接时跳转到锚点。
我目前正在使用
window.location = '#top';
它在 FF、Opera 和 Chrome 中按预期工作,但在 IE 7 中不正常。
我已经尝试了所有排列,例如 window.location.hash 和 window.location.assign() 以及 scrollIntoView(true) 和 focus()。
我怎样才能让它在 IE 中工作?
编辑:似乎没有任何效果,这让我认为这不是语法,而是关于 JS 的一些东西......这是点击事件处理程序......可能是因为它返回 false 吗?我正抓着稻草。
// Click handler for each location link
$('#index a').click(function()
{
hideMarkers();
location.href = location.href + "#top";
var marker = showMarker( $(this).attr('data-id') );
GEvent.trigger( marker, "click" );
return false;
});
编辑:分配给 window.location.hash 在 IE7 和 IE8 中由于通过 HTTP“位置”标头进行页面重定向而加载的页面上的中断。解决方案是返回一个带有 Javascript 的页面,该页面本身将执行重定向。请参阅乔拉普的答案。