| <!DOCTYPE html> |
| <html> |
| <body> |
| Open this page through a web server in two views. If necessary request permission to post web notifications: <button onclick="requestPermission()">Request permission</button><br/> |
| Then post this permission once in each page. <button onclick="postNotification()">Post notification</button><br/> |
| Click on the notification. Only the second notification should be closed on the second page. |
| <p id="console"> |
| </p> |
| |
| <script> |
| function requestPermission() { |
| if (Notification.permission == "granted") { |
| log("Notification already granted"); |
| return; |
| } |
| |
| log("Requesting permission..."); |
| Notification.requestPermission(function(permission) { |
| if (Notification.permission == "granted") { |
| log("Notification granted"); |
| return; |
| } |
| log("Notification denied"); |
| }); |
| } |
| |
| function postNotification() { |
| var n = new Notification("Notification title"); |
| n.onshow = onShowHandler; |
| n.onclick = onClickHandler; |
| n.onclose = onCloseHandler; |
| } |
| |
| function log(message) { |
| document.getElementById("console").innerHTML += message + "<br/>"; |
| } |
| |
| function onShowHandler() { |
| log("onshow handler called"); |
| } |
| |
| function onClickHandler() { |
| log("onclick handler called"); |
| this.close(); |
| } |
| |
| function onCloseHandler() { |
| log("onclose handler called"); |
| } |
| </script> |
| </body> |
| </html> |