Html5 notification system, javascript

Asked

Viewed 669 times

0

I would like to understand more about this system, however, no publication helped me. I already know how to create a notification

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <h1>Notificações</h1>
    <input type="button" value="Notificar!" onclick="minhaNotificao()">
    <script>
        //Verifica e solicita se o usuario tem permissao para utilizar as notificações do Chrome
        document.addEventListener('DOMContentLoaded', function () {
            if (!Notification) {
                alert('Erro no sistema de notificação, navegador não suportado.');
                return;
            }

            if (Notification.permission !== "granted")
                Notification.requestPermission();
        });

        function minhaNotificao() {
            if (Notification.permission !== "granted") {
                Notification.requestPermission();
            }
            else {
                var notificacao = new Notification("Titulo da notificacao", {
                    icon: 'go.jpg', //img
                    body: 'Mensagem'
                });

                notificacao.onclick = function () {
                    window.open('http://google.com/'); //site
                };
            }
        }

        minhaNotificao();
    </script>
</body>

</html>

However, I would like to create a real-time notification system (without using the website offering this service). Would you create a database in php and mysql, with the messages, something like that? Would the browser check this database? How does the notification system currently work? Do you need a server? HELP, lost in it.

  • I’m thinking of creating a server in Nodejs... ?

  • I would like to understand the logic of notification system, push notification. How does it work? What do I have to do to create a real-time notification system? Do I need a server? How does the browser check the server?

  • The user would not receive if the page was not open, right :( ?

  • It wouldn’t be useful in my case, thank you :(

  • You might as well use the.site popkit for this. Just add 3 lines of code and the rest you do in the control panel. Full control of views for the user and design. And the best: Unbranded in the footer, fully clean to be embedded in your site.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.