简体   繁体   English

$(window).on(“ focus”,…)在chrome手机上不起作用

[英]$(window).on(“focus”, …) not working on chrome mobile

There´sa question asking for the same, but it doesn't have a satisfactory answer as I already tried it. 有一个问题要问同样的问题,但是我已经尝试过了,但没有令人满意的答案。

This is my code: 这是我的代码:

$(window).on("focus", function() {
    doSomeFunction();
    alert("I am here!");
});

I'm using window because document wasn't working even on chrome desktop, someone suggested using window here in stackoverflow and it works on desktop at least, but in chrome mobile is another case. 我之所以使用window,是因为文档甚至在chrome桌面上也无法正常工作,有人建议在stackoverflow中使用window,它至少可以在桌面上使用,但是在chrome mobile中则是另一种情况。

With firefox mobile I can switch tabs, press home and reopen firefox, press home, swipe close and reopen firefox and I get the alert message, with chrome none of those cases work. 使用firefox mobile,我可以切换选项卡,按home键并重新打开firefox,按home键,滑动关闭并重新打开firefox,然后我得到警报消息,但在所有情况下都无法使用chrome。

Need to find a way to make it work on that browser, remember, it works on chrome and firefox desktop and firefox mobile but not on chrome mobile. 需要找到一种使其在该浏览器上运行的方法,请记住,它只能在chrome和firefox桌面以及firefox移动版上运行,而不能在chrome移动版上运行。

Thanks in advance 提前致谢

Got a solution, it's probably not the best but it works. 得到了一个解决方案,它可能不是最好的,但它可以工作。

Aparently chrome mobile is not catching this event when is placed on .js files so I just have to place it on a tag in my html document: 当放在.js文件上时,显然chrome mobile无法捕获此事件,因此我只需要将其放在html文档中的标签上即可:

<script>
    $(window).on("focus", function() {
        doSomeFunction();
        alert("I am here!");
    });
</script>

In this case, it doesn't matter if doSomeFunction() is in the DOM or in a .js file, just make sure the focus event is in the DOM 在这种情况下,doSomeFunction()是在DOM中还是在.js文件中都没有关系,只需确保焦点事件在DOM中即可

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

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