1
I wonder how I can make to run a script (in this case are those desktop notifications) only if the user is not open tab, I mean, I want to send a desktop notification to it only if it’s not open (I’m doing it with ajax) but I don’t know how to do it in javascript! I tried to use:
$(window).focus(function(){
//your code
});
but it didn’t 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);
}
});
});
I used . focusout but it did not work, now it does not send the notification, I will edit the question and put the full code!
– Leonardo
It’s just that I don’t really care when he left, I just need to check whether the tab is open or not
– Leonardo
tried with the Blur?
– Felipe Assunção
I tried and I didn’t either, but I managed to solve!
– Leonardo