当页面加载是 AJAX 历史点的结果时,如何检测客户端?

发布于 2024-09-03 08:09:15 字数 363 浏览 3 评论 0原文

我试图防止 ASP.NET 页面上出现“闪烁”效果,当用户导航离开该页面后通过浏览器后退按钮导航到该页面时,就会发生这种情况。闪烁的原因是我正在使用更新面板,其中在初始页面加载时包含一些内容。因此,当通过后退按钮加载页面时,初始内容会非常简短地显示,然后才会使用正确的历史感知数据进行更新。

为了克服这个问题,我打算在初始页面加载时隐藏更新面板(显示:无),然后只要我们没有任何历史记录需要处理,就显示它。问题是我不知道要检查什么来确定是否有任何历史记录。我可以看到 Sys.Application 有一个 _history 成员,但是当我在 init 页面上检查它时,它每次都是 null。

有谁知道我应该检查什么以确定是否有页面加载客户端需要处理的历史记录?以及什么时候做呢?

I'm trying to prevent a "flicker" effect that is occurring on my ASP.NET page which occurs when a user navigates to the page via the browser back button after having navigated away from it. The reason for the flicker is that I'm using an Update Panel which has some content in there on the initial page-load. As a result, when the page is loaded via a back button that initial content is shown very briefly before it is updated with the correct History-aware data.

In order to overcome this I am intending on having the updatepanel hidden (display: none) on inital page load and then show it as long as we don't have any history to deal with. The problem is that I can't find out what to check to determine if there's any history. I can see that the Sys.Application has a _history member but when I'm checking it on page init it is null each time.

Does anyone know what I should be checking to determine if there's history to deal with for a page load client-side? And at what point to do it?

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

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

发布评论

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

评论(3

青衫负雪 2024-09-10 08:09:15

浏览器的后退按钮及其提供的功能完全独立于网页的内容。

您可以做的一件事是在进行 AJAX 更新时设置您的位置哈希。当您加载页面时,您也许能够检测到这一点。我没试过。您应该能够在服务器端解析出 url 的 # 部分,并查看您在 AJAX 历史记录中的位置。

location.hash = 'foo';

The browser's back button and the functionality that it provides is completely independent of the content of your web page.

One thing you might be able to do is set your location hash when you do an AJAX update. You might be able to detect this when you load a page. I haven't tried it. You should be able to parse out the # portion of the url on the Server Side and see where you are in the AJAX history.

location.hash = 'foo';
乱世争霸 2024-09-10 08:09:15

感谢您的回复丹尼尔。现在,我的更新面板周围有一个 div,其显示属性设置为 none。在 Sys.Application 的 init 事件中,我检查 window.location.hash 值以确定页面加载是否是浏览器后退/前进按钮单击的结果。如果不是,那么我将显示属性设置为阻止,如果不是,我暂时将其保留为“display: none”。

在服务器端的 ScriptManager Navigate 事件处理程序中,由于单击后退按钮而调用该事件处理程序,我正在注册一个客户端脚本块,它将显示属性设置为阻止。

我已经做了一些测试,似乎工作正常,并且不再出现闪烁。我更喜欢使用 MS AJAX 客户端对象之一来检查历史记录,但我们就这样了。

Thanks for your response Daniel. I now have a div around my update panel which has its display property set to none. On the Sys.Application's init event I'm checking the window.location.hash value to determine whether the page load is the result of a browser back/forward button click. If it isn't then I'm setting the display property to block, if not I leave it as 'display: none' for the time being.

On the server-side in the ScriptManager Navigate event handler which is called as a result of the back button being clicked I'm registering a client script block which sets the display property to block.

I've done a bit of testing and seems to work fine and I no longer get the flicker. I would prefer to use one of the MS AJAX client objects to check for history but there we are.

筑梦 2024-09-10 08:09:15

在页面中放置一个带有空白值的隐藏输入,然后在页面加载时设置其值。您会发现,当使用后退按钮时,页面加载脚本会发现该值仍然设置,您可以做出相应的响应。这利用了浏览器功能在页面加载之间保留表单内容。

Put a hidden input in the page with a blank value, and then on page load set its value. You'll find that when using the back button the page load script will find the value is still set and you can respond accordingly. This takes advantage of browser functionality that preserves form contents between page loads.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文