简体   繁体   中英

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 ');

myWindow.onblur = function(){ alert('myWindow lost focus'); }

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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