Show warning on all pages whenever button is clicked

This is a basic example of my question.

I have two or more html pages that look like

page1.html

<script src='notify.js'></script>
<h2>Page 1</h2>
<button id='btn' onclick='notify();'>Click</button> 

page2.html

<script src='notify.js'></script>
<h2>Page 2</h2>

etc.

my js file notify.js

function notify(){
alert("button clicked");
}

In page1.html is button. When I click buttonmessage alertshould be displayed on all pages. How can I achieve this?

In page1.html the message is alertshown successfully. But I need to show the message alerton all pages, whenever it is clicked button(in page1.html ).

This is similar to the notification process. I think someone can help me.

+4
4

, . .

, 1, ajax, DB, .

$.ajax({url: "/addAlertMessageToDB.php", success: function(result){
       alert("message written to DB");
    }});

, , JS ajax, setInterval

setInterval(function(){ 

    $.ajax({url: "/getLatestMessage.php", success: function(result){
            alert(result);
        }});


}, 3000);

, ajax 3 , .

- .

select id,message,readFlag from messagesTable where readFlag = false

, ..

+1

, . , , JavaScript.

:

  • Ajax , , . , .
  • websockets. , . "push" -.
+1

:

  • Long Polling Forever Frame.
  • Ajax .
  • HTML5 WebSocket.
  • SignalR ( .Net) WebSocket, , .

, . -, , , , - .

0

"", , ,

So: - , XMPP, websockets, socket ..

1 listner as well as 1 publisher per page

listner will listen to notifications and respond; the publisher will broadcast notifications (your button)

-1
source

Source: https://habr.com/ru/post/1617372/


All Articles