Executing a javascript function in different computers at same time

I would like to execute a Javascript function in two different computers at same time. I am going to name them as master and slave computer.

The idea is that when I press a button in the master computer, a javascript function is executed in both computers at same time.

Master and slave would connected to an identificative URL like: domain.com/master_idnumberXXX and master.com/slave_idnumberXXX

So I think I need some RTC protocol or something like that, I have been reading about it but feel a little lost and I would like to know what would be my best option. I've been reading about node.js and similar stuff (webrtc) and for this 'simple' subject I do not know if would be 'too much'.

Thanks in advance and sorry about my un-experience about this field.

You could use WebSocket, though be aware of potential problems (which is a good reason to use Socket.io, as already recommended, which provides fallbacks and workaround).

RTCDataChannel leverages RTCPeerConnection to enable peer-to-peer communication of arbitrary data with very low latency -- and as part of WebRTC, it's designed to cope with NATs and firewalls. (More information here, press P for speaker notes -- apologies for shameless self promotion!) RTCDataChannel is used by the wonderful Cube Slam game.

Another option is to use XHR plus the Google Channel API: apprtc.appspot.com uses this for messaging, code here.

If you use socket.io on a server you can do something like this.

On the master

var socket = io.connect();
//button press function
function buttonPress(){
    //do logic
    socket.emit("button pressed");
}

On the slave

var socket = socket.connect();
socket.on("button pressed", handlePress);

function handlePress(){
    //do your logic
}