简体   繁体   English

为什么 iOS Safari 两次触发窗口焦点事件?

[英]Why does iOS Safari fire window focus event twice?

I have the following code on a page:我在页面上有以下代码:

var i = 0;
window.addEventListener("focus", function(event) { 
  document.body.innerHTML = "Focus count = " + i++;
}, false);

On desktop this increments correctly (1,2,3 etc) when switching tabs (or any window blurring/focusing action)在桌面上,当切换选项卡(或任何窗口模糊/聚焦操作)时,这会正确增加(1、2、3 等)

However, when I switch tabs on ios safari the event appears to be firing twice (1,3,5,7 etc)但是,当我在 ios safari 上切换选项卡时,该事件似乎触发了两次(1、3、5、7 等)

Why is this happening?为什么会这样?

ATTOW the reason is unknown, but this is a known issue in Webkit: ATTOW 原因未知,但这Webkit 中的一个已知问题:

https://bugs.webkit.org/show_bug.cgi?id=179990 https://bugs.webkit.org/show_bug.cgi?id=179990

From above:从上面:

With two or more text inputs on a form, switching focus by click from one to another sometimes causes an extra focus/blur to fire.对于表单上的两个或多个文本输入,通过单击将焦点从一个切换到另一个有时会导致额外的焦点/模糊触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM