I have two web pages as follows, when i click a button in one page alert box should be displayed in both pages, How can i achieve this. How can i click two buttons in two different web pages at once
app.js
var express = require('express');
var app = express();
var serv = require('http').Server(app);
app.get('/',function(req, res){
res.sendFile(__dirname + '/client/index.html');
});
app.use('/client',express.static(__dirname + '/client'));
serv.listen(2000);
console.log("server started");
var SOCKET_LIST ={};
var io = require("socket.io")(serv,{});
io.sockets.on("connection", function(socket){
socket.id = Math.random();
SOCKET_LIST[socket.id] = socket;
console.log("socket connection");
socket.on('disconnect',function(){
delete SOCKET_LIST[socket.id];
console.log("Disconnected");
});
socket.on("button",function myFunction() {
alert("I am an alert box!");
});
socket.emit('servermsg', $("button").click(function() {
alert("I am an alert box!");
}));
});
setInterval(function(){
for(var i in SOCKET_LIST){
var socket = SOCKET_LIST[i];
}
}, 1000/25);
index.html (client)
<!DOCTYPE html>
<html>
<body>
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script>
var socket =io();
socket.emit('button',function myFunction() {
alert("I am an alert box!");
});
socket.on('servermsg', function(data){
console.log(data.msg);
});
</script>
<p>Click the button to display an alert box:</p>
<button onclick="myFunction()">Try it</button>
</script>
</body>
</html>