不活动时停止 UpdatePanel
您好,我想执行以下操作:
当浏览器处于非活动状态时,使用 JavaScript 停止更新面板“更新”,并在浏览器再次活动后重新启动。 我正在查看:Inacivity with JavaScript。 我希望我能用它来完成我想要的事情; 有人能指出我正确的方向吗? 非常感谢!
[编辑] 我正在使用计时器进行更新,因此如果我可以以某种方式从 JavaScript 禁用计时器,我想我可以做到这一点。
Hi I would like to do the following:
Use JavaScript to stop the update panel from "updating" when the browser is inactive, and restart once it’s active again. I was looking at: Inacivity with JavaScript. I was hoping that I could use this to accomplish what I want; can someone point me in the right direction? Thank you very much!
[EDIT]
I am using a Timer for the updates so if I can somehow disable the Timer from JavaScript I think I can do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我建议阅读这本书:http://oreilly.com/catalog/9780596527471/。 它告诉您需要了解的有关 ASP.NET AJAX UpdatePanel 控件的所有信息。 有关 API 文档,请访问:http://msdn.microsoft.com/nb-no/library/ bb311028(en-us).aspx。
I recommend reading this book: http://oreilly.com/catalog/9780596527471/. It tells you everything you need to know about the ASP.NET AJAX UpdatePanel Control. For API documentation please visit: http://msdn.microsoft.com/nb-no/library/bb311028(en-us).aspx.
如何利用当前窗口对象的“mousemove”事件?
如果鼠标已移动,请将计时器设置为 1 分钟左右,然后停用事件。
使用 setInterval() 重复此循环。
如果用户小睡了一段时间,这也会有所帮助。
What's about taking advantage of current window object's 'mousemove' event?
If mouse has been moved, set the timer for 1 min or so, and deactivate event.
Repeat this cycle using setInterval().
It would also help, if the user had snoozed for a while.
浏览器兼容性可能适用。 希望这可以帮助。
browser compatibility may apply. Hope this helps.
我在这里找到了一个潜在的解决方案: http://www.thefutureoftheweb.com/blog /detect-browser-window-focus
我现在只有 IE8 可以测试,它有几个问题。 首先,单击页面上的各个元素将触发 focusin 事件,因此您需要一种方法来检查计时器是否已经在运行。 这并不太难。 当您点击时,ie8 还会触发 focusout 事件,因此我们必须延迟实际的计时器停止,以确保窗口实际上没有焦点。 幸运的是,当您点击页面时,ie8 似乎总是在
focusout
之后立即触发focusin
,因此我们可以取消focusin
上待处理的计时器关闭> 处理程序。我认为这应该非常接近一个可行的解决方案。 (改编自链接)
I found a potential solution here: http://www.thefutureoftheweb.com/blog/detect-browser-window-focus
i only have IE8 to test with right now, which has a couple issues. first, clicking around the various elements on a page will fire the
focusin
event, so you need a way to check if the timer is already running. that's not too hard. ie8 also fires thefocusout
event while you're clicking around, so we have to delay the actual timer stoppage to make sure the window doesn't actually have focus. fortunately ie8 appears to always firefocusin
right afterfocusout
while you're clicking on the page, so we can cancel a pending timer shutdown on thefocusin
handler.i think this should be pretty close to a working solution. (adapted from the link)
在 head 事件中添加此脚本,
在更新面板内添加一个 asp.net 标签控件用于测试
在更新面板外添加一个 html 按钮
以检查计时器是否停止在 aspx.cs 文件中添加此代码
只需省略 (") 标记在脚本中,因为它会导致错误......
add this script inside the head event,
add an asp.net label control inside the update panel for testing
add an html button outside the update pannel
to check if the timer stops add this code in aspx.cs file
Just omit the (") mark in the Script because it will cause an error...