Skip to content

Instantly share code, notes, and snippets.

@iespino00
Created March 13, 2018 00:32
Show Gist options
  • Save iespino00/d18ef500b47f5508036e7b2da7455618 to your computer and use it in GitHub Desktop.
Save iespino00/d18ef500b47f5508036e7b2da7455618 to your computer and use it in GitHub Desktop.
Notifications javascript
<?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