Created
March 13, 2018 00:32
-
-
Save iespino00/d18ef500b47f5508036e7b2da7455618 to your computer and use it in GitHub Desktop.
Notifications javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ipphp = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; | |
echo '<script>var ip= "'.$ipphp.'";</script>'; | |
?> | |
<head> | |
<meta charset="utf-8"> | |
<title>Ejemplo de notificaciones</title> | |
</head> | |
<body> | |
<button onclick="notificar();" >Enviar notificación</button> | |
<script> | |
console.log(ip); | |
if(Notification.permission !== "granted") | |
{ | |
Notification.requestPermission(); | |
} | |
document.cookie ='notification='+ip+'; max-age=3600; path=/'; | |
// document.cookie = "notification=; max-age=0; path=/"; | |
function notificar() | |
{ | |
console.log(Notification.permission); | |
if(Notification.permission !== "granted") | |
{ | |
Notification.requestPermission(); | |
} | |
else{ | |
var notificacion = new Notification("Titulo", | |
{ | |
icon: "logo.png", | |
body: "Notificación de Grupo Fertinal:"+ip | |
} | |
); | |
notificacion.onclick = function() | |
{ | |
window.open("http://10.3.11.10"); | |
} | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment