从回发返回时加载 URI 中包含目标的页面

发布于 2024-12-02 15:17:58 字数 681 浏览 1 评论 0原文

我在网页上有多个段,用目标标识,如下所示:

<div id="target1" class="section">
          <h4><a href="#target1">Buildings by Name</a></h4>
          <div>

              // button to call server side function
          </div>
</div>

因此,当用户单击“按名称排列的建筑物”时,URI 更改为 http://www.mydomain.com/page.aspx#target1

我需要打电话服务器端函数,它将进行一些处理。当我从服务器端脚本返回时,我想使用相同的目标 URI 重新加载页面 http://www.mydomain.com/page.aspx#target1 。现在,当我从回发返回时,URI 只是 /page.aspx

有没有办法做到这一点?

谢谢!

I have multiple segments on a web page, identified with targets, like this:

<div id="target1" class="section">
          <h4><a href="#target1">Buildings by Name</a></h4>
          <div>

              // button to call server side function
          </div>
</div>

So when user clicks "Buildings by Name", the URI changes to
http://www.mydomain.com/page.aspx#target1

i need to call a server side function, which will do some processing. And when i return from the server side script, i want to reload the page with the same targeted URI
http://www.mydomain.com/page.aspx#target1 . Right now, when I return from the postback, the URI is just /page.aspx

is there a way to do this?

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月如刀 2024-12-09 15:17:59

我会沿着 AJAX 路线走下去。基本上,使用 JavaScript 覆盖标记上的点击处理程序,运行对服务器的调用,并将响应中的数据填充到您的 .

我是执行这些任务的 jQuery 库的粉丝,但是有很多很棒的工具可以提供帮助。

还有一些关于使用 jQuery 进行 AJAX 的教程:

http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/
http://www.sitepoint.com/ajax-jquery/

I would go down the AJAX route with this. Basically, use JavaScript to override the click handler on your tag, run a call to the server, and populate the data from the response into your .

I'm a fan of the jQuery library for these tasks, but there's a slew of great tools out there to help.

And some tutorials on doing AJAX w/ jQuery:

http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/
http://www.sitepoint.com/ajax-jquery/

梦中的蝴蝶 2024-12-09 15:17:58

我找到了一种方法来做到这一点。虽然不是最迷人的,但似乎很有效。我用这篇文章作为指导:
以编程方式滚动到锚点标签

因此,在服务器端代码中,处理后,我调用了一个javascript函数:
ClientScript.RegisterStartupScript(this.GetType(), "滚动",
“scrollToResults()”);

然后,在aspx页面中,我放入了javascrpt函数:

<Script>
function scrollToResults() {
         // next 2 lines work on desktop browsers, but not mobile
         // var el = document.getElementById("target1");
         // el.scrollIntoView(true);

         // this bit will work for most mobile browsers
            window.location.href = window.location.protocol + "//" + window.location.host +
                   window.location.pathname + window.location.search +
                   "#target1";
  }
  </script>

I found a way to do this. Not the most glamorous, but it seems to work. I used this post as a guide:
Programmatically scroll to an Anchor Tag

So, in the server side code, after processing, I called a javascript function:
ClientScript.RegisterStartupScript(this.GetType(), "scrolling",
"scrollToResults()");

Then, in the aspx page, i threw in the javascrpt function:

<Script>
function scrollToResults() {
         // next 2 lines work on desktop browsers, but not mobile
         // var el = document.getElementById("target1");
         // el.scrollIntoView(true);

         // this bit will work for most mobile browsers
            window.location.href = window.location.protocol + "//" + window.location.host +
                   window.location.pathname + window.location.search +
                   "#target1";
  }
  </script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文