-1

i want to send desktop notification for my website visitor after the close my website

how can i make them subscribe ? and how to send the notification for them all

this website make the same jeapie.com, but i want to make my own

i have seen some code but it send notification for me only

if (event.target.id === 'button-wn-show-preset') {
  // Uses the preset parameters
} else {
  // Uses the custom parameters
}
fares r
  • 1
  • 1
  • your question is too broad to answer. If you really want to make yout own notification system I suggest you look for a tutorial and start building it. Then ask specific questions about problems you run into, providing code examples and explaining what have you tried to achieved and why do you think it's not working. – ithil Sep 02 '15 at 15:11

1 Answers1

0

It seems like you want something like the onbeforeunload event handler in JavaScript. When the user navigates away from the page there will be a JS popup warning. Check out the W3 Reference for the usage.

example from link above:

<!DOCTYPE html>
<html>
<body onbeforeunload="notifyMe()">


<script>
// request permission on page load
document.addEventListener('DOMContentLoaded', function () {
    if (Notification.permission !== "granted")
        Notification.requestPermission();
});

function notifyMe() {
    if (!Notification) {
        alert('Desktop notifications not available in your browser. Try Chromium.'); 
        return;
    }

    if (Notification.permission !== "granted")
        Notification.requestPermission();
    else {
        var notification = new Notification('Notification title', {
        icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
        body: "Hey there! You've been notified!",
    });

    notification.onclick = function () {
        window.open("http://stackoverflow.com/a/13328397/1269037");      
    };
  }
}
</script>

</body>
</html>
GHandel
  • 172
  • 2
  • 3
  • 13
  • thank you for your comment, but not that i want , what i want desktop notification . here an example http://jsbin.com/ziwod/2/edit?html,js,output – fares r Sep 02 '15 at 15:22
  • I've edited my answer to use the code from your jsbin. It should work to push a notification when the user navigates from the page. – GHandel Sep 02 '15 at 16:05