从浏览器检测 iPad 上的主页按钮点击事件

发布于 2025-01-05 06:46:10 字数 144 浏览 4 评论 0原文

如何检测 iPad2 上的主页按钮点击?

当在 iPad2 上单击主页按钮时,我的应用程序需要发送更新服务器。

我尝试通过 jQuery 卸载、调整事件大小,但没有任何结果被触发。我在普通浏览器和从“添加到主屏幕”的链接上都尝试过相同的操作。

How can I detect the home button click on iPad2?

My application needs to send update the server when the home button is clicked on iPad2.

I have tried unload, resize event through jQuery, but nothing gets fired. I have tried the same on both normal browser and link from add to home screen.

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

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

发布评论

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

评论(3

半葬歌 2025-01-12 06:46:10

您无法检测到按下主页按钮。您可以尝试当窗口/主体失去焦点时,这不能保证有效,因为我还没有测试过它。它还可能捕获其他事件,例如切换选项卡、关闭窗口等。

类似这样的可能可以工作

$('body').blur(function() {
  // do something
});

You can't detect a press on the home button. You could try for when the window/body loses focus, this isn't guaranteed to work though as I haven't tested it. It might also catch other events like switching tabs, closing the window etc.

Something like this may work

$('body').blur(function() {
  // do something
});
后来的我们 2025-01-12 06:46:10

如果 Safari 中没有此类事件,则无法触发该事件。
由于网站未卸载,卸载将不起作用。

您可以尝试构建某种心跳机制并检查您的服务器是否某个客户端已停止发送心跳。

There's no way to fire an Event if there's no such Event in Safari.
unload won't work as the Site isn't unloaded.

You can try to build some sort of heartbeat mechanism and check on your server, if a certain client has stopped sending heartbeats.

愛放△進行李 2025-01-12 06:46:10

窗口上的焦点和模糊事件可以很好地检测浏览器是否要进入后台或从后台返回。

window.addEventListener("focus", function(evt){
    console.log('show');
}, false);
window.addEventListener("blur", function(evt){
    console.log('hide');
}, false);

The focus and blur events on the window are good to detect if the browser is going to or back from background.

window.addEventListener("focus", function(evt){
    console.log('show');
}, false);
window.addEventListener("blur", function(evt){
    console.log('hide');
}, false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文