Mobile Safari/Webkit 窗口焦点事件

发布于 2024-09-25 08:00:47 字数 175 浏览 0 评论 0原文

我想知道当用户切换回“您的”页面窗口时是否有可能收到事件?当用户打开新选项卡然后切换回页面的选项卡或用户关闭 safari 然后再次打开它时,可能会发生这种情况。

我希望能够在收到此事件后更新页面上的内容。我现在使用 setInterval 来完成此操作,但是当用户专注于您的窗口时最好没有延迟。

谢谢!

I am wondering if it is possible to get a event when the user switches back to "your" page's window? This could happen either when the user opens a new tab and then switches back to your page's tab or when the user closes safari and then opens it again.

I want to be able to update content on the page once I get this event. I am using a setInterval to accomplish this now, but it would be nice to not have the delay when the user focuses on your window.

Thanks!

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

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

发布评论

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

评论(2

摘星┃星的人 2024-10-02 08:00:47

这个问题得到解决的可能性似乎很小:

我创建了 this 脚本来记录尽可能多的 WebKit 事件(事件名称取自 http://svn.webkit.org /repository/webkit/trunk/Source/WebCore/dom/EventNames.h),并且在离开/带到前台 Safari 时似乎不会触发任何事件。

The chance of this one getting resolved seems small:

I created this script to log as many WebKit events as possible (event names taken from http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/dom/EventNames.h), and it doesn't seem to trigger any event upon leaving/bringing to front Safari.

椒妓 2024-10-02 08:00:47

我一直在深入研究,发现再次激活窗口时会触发 focus 事件。

它应该是可行的(使用 jQuery):

$(window).on('focus', function() {
    ...focus code here...
});

这个事件可能比需要的更频繁地触发,但它对我有用。

I've been digging around and found that a focus event is fired when the window is activated again.

It should be doable like this (using jQuery):

$(window).on('focus', function() {
    ...focus code here...
});

This event is probably fired more often than needed, but it worked for me.

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