Javascript Anchor跳到最热门的问题

时间:2010-08-11 20:04:36

标签: c# javascript asp.net sharepoint

我已将此代码添加到OnPreRender()方法中的MOSS 2007 Web部件中。

if (!Page.ClientScript.IsClientScriptBlockRegistered("jump_to_anchor_JS"))
{
   Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jump_to_anchor_JS", "window.location.hash=\"anchor\";",true);
}

页面加载,跳转到特定锚点,然后跳回页面顶部。 这已经在IE8,Firefox,Chrome和Safari中进行了相同的测试。

有什么想法吗?

3 个答案:

答案 0 :(得分:0)

尝试使用:

ClientScript.RegisterStartupScript(...)

来自MSDN文章here

  

由...呈现的脚本块   RegisterStartupScript方法   页面完成时执行   加载但在页面的客户端之前   引发了onload事件。启动脚本   块位于底部   之前呈现的ASP.NET页面   表格标签。

或使用jQuery:

$(document).ready(function(){window.location.hash="anchor";});

答案 1 :(得分:0)

您是否在主播名称前加上“#”井号?即,

window.location.hash = '#anchor';

另外,请参阅window.location.hash issue in IE7关于使用focus()或scrollIntoView()的信息。

答案 2 :(得分:0)

尝试使用

window.location.href ='#anchor';

相关问题