I would like to know how I can do to run a script (in this case it is those desktop notifications) only if the user does not have the open tab , ie I want to send a desktop notification to it only if it does not have the site open (I'm doing this with ajax) but I do not know how to do this in javascript! I tried using:
$(window).focus(function(){ //your code });
But it did not work ...
Thank you!
Complete code:
$(window).focusout(function() { Notification.requestPermission(function (permission) { // Whatever the user answers, we make sure we store the information if (!('permission' in Notification)) { Notification.permission = permission; } // If the user is okay, let's create a notification if (permission === "granted") { var options = { body: "TEXTO_DA_NOTIFICACAO", icon: "IMAGEM", dir : "ltr" }; var notification = new Notification("TITULO",options); } }); });