Skip to content

Instantly share code, notes, and snippets.

@evilnapsis
Created March 20, 2021 05:52
Show Gist options
  • Save evilnapsis/676d27ea771d42d884dc957fb04bd84a to your computer and use it in GitHub Desktop.
Save evilnapsis/676d27ea771d42d884dc957fb04bd84a to your computer and use it in GitHub Desktop.
Ejemplo de notificaciones de escritorio desde el navegador ... by Evilnapsis
<!DOCTYPE html>
<html>
<head>
<title>Notifications</title>
</head>
<body>
<h1>Notifications</h1>
<br>
<button id="not1">Notificacion 1</button>
<button id="not2">Notificacion 2</button>
<script type="text/javascript">
Notification.requestPermission().then(function(result) {
console.log(result);
});
document.querySelector("#not1").onclick = function(){
if (Notification.permission === "granted") {
var notification = new Notification("Hola notificacion1 !");
}else {
alert("No aceptaron las notificaciones.");
}
}
document.querySelector("#not2").onclick = function(){
if (Notification.permission === "granted") {
var options = {
body: "Notificacion2 con imagen y evento",
icon: "motocross1.jpg"
}
var notification2 = new Notification("Nueva notificacion!", options);
notification2.onclick = function(e){
var notification3 = new Notification("Gracias por hacer click en la notificacion 2");
}
}
}
// powered by Evilnapsis
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment