如何实现ASP.NET中的导航到特定代码锚点功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计270个文字,预计阅读时间需要2分钟。
我有一个简单的Web窗体,代码如下: Test POST后我想导航用戶到我的主页消
我有一个简单的Web窗体,代码如下://... //tons of text //... <a name="message" /> //... //tons of text //... <asp:Button ID="ButtonSend" runat="server" text="Send" onclick="ButtonSend_Click" />
POST后我想导航用户到我的主播“消息”.我有以下代码:
protected void ButtonSend_Click(object sender, EventArgs e) { this.ClientScript.RegisterStartupScript(this.GetType(), "navigate", "window.location.hash='#message';", true); }
这个简单的JavaScript在Firefox 3.5.2中不起作用 – url在浏览器中更改但页面未导航到锚点.在IE 8中它完美运行.
为什么这个JavaScript代码在Firefox中不起作用?我错过了什么吗?
我已经解决了我的问题.在我的锚点存在之前调用了JavaScript代码.这就是Firefox没有滚动页面的原因.我的代码现在看起来像tihs:
this.ClientScript.RegisterStartupScript(this.GetType(), "navigate", "window.onload = function() {window.location.hash='#message';}", true);
页面加载后,我正在调用我的简单JavaScript函数.
找到解决方案的关键是克莱顿回答. Firebug报告getElementById返回null引用.然后我查看生成的HTML,就像andrewWinn建议的那样 – 在锚点存在之前调用了JavaScript.做了一点谷歌搜索并找到了解决方案.
谢谢你的回答!
本文共计270个文字,预计阅读时间需要2分钟。
我有一个简单的Web窗体,代码如下: Test POST后我想导航用戶到我的主页消
我有一个简单的Web窗体,代码如下://... //tons of text //... <a name="message" /> //... //tons of text //... <asp:Button ID="ButtonSend" runat="server" text="Send" onclick="ButtonSend_Click" />
POST后我想导航用户到我的主播“消息”.我有以下代码:
protected void ButtonSend_Click(object sender, EventArgs e) { this.ClientScript.RegisterStartupScript(this.GetType(), "navigate", "window.location.hash='#message';", true); }
这个简单的JavaScript在Firefox 3.5.2中不起作用 – url在浏览器中更改但页面未导航到锚点.在IE 8中它完美运行.
为什么这个JavaScript代码在Firefox中不起作用?我错过了什么吗?
我已经解决了我的问题.在我的锚点存在之前调用了JavaScript代码.这就是Firefox没有滚动页面的原因.我的代码现在看起来像tihs:
this.ClientScript.RegisterStartupScript(this.GetType(), "navigate", "window.onload = function() {window.location.hash='#message';}", true);
页面加载后,我正在调用我的简单JavaScript函数.
找到解决方案的关键是克莱顿回答. Firebug报告getElementById返回null引用.然后我查看生成的HTML,就像andrewWinn建议的那样 – 在锚点存在之前调用了JavaScript.做了一点谷歌搜索并找到了解决方案.
谢谢你的回答!

