简体   繁体   English

我的函数 window.onblur,不能使用外部链接

[英]My function window.onblur, not working with external links

I have the following problem, when I open a link of my host, my function to detect the loss of focus works fine, but when I execute an external link, it does not work ... why does this happen?我有以下问题,当我打开主机的链接时,我检测失去焦点的功能工作正常,但是当我执行外部链接时,它不起作用......为什么会发生这种情况?

var myWindow = window.open(' https://www.google.com.ar '); var myWindow = window.open(' https://www.google.com.ar ');

myWindow.onblur = function(){ alert('myWindow lost focus'); myWindow.onblur = function(){ alert('myWindow 失去焦点'); } }

I'm just looking to know if the open external link is observed or not!我只是想知道是否观察到打开的外部链接!

You can add an event listener for the visibilitychange event of the document of the opened window.您可以为打开窗口的文档的visibilitychange事件添加一个事件监听器。

myWindow.document.addEventListener('visibilitychange', function(event){
    if(this.hidden){
        alert('myWindow is hidden');
    }
});

JSFiddle Demo: https://jsfiddle.net/r3hvet8m/ JSFiddle 演示: https ://jsfiddle.net/r3hvet8m/

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

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