javascript - Receiving returned message from web socket in another browser -


i have 2 separate pages, each opens web socket server, 1 pages fires message server, there way other page can receive reply? appreciated.

thanks

first page, connects , waits message

<html> <head> <script type="text/javascript" charset="utf-8">     if("websocket" in window) {         var ws = new websocket("ws://localhost:12345/server.php");     }     function startsocket() {         if("websocket" in window) {             ws.onopen = function (event) {                 document.getelementbyid('status').innerhtml = "open: " + this.readystate;             }              ws.onmessage = function (message) {                 alert(message.data);                 }         }     } </script>  </head> <body onload="startsocket()"> <div id="status">  </div> <div id="stock">  </div> </body> </html> 

second page sends message server via web scoket

<html> <script type="text/javascript" charset="utf-8">     if("websocket" in window) {         var ws = new websocket("ws://localhost:12345/server.php");     }     function startsocket() {         if("websocket" in window) {             ws.onopen = function (event) {                 document.getelementbyid('status').innerhtml = "open: " + this.readystate;             }          }     }     function send() {                        var text = "hello";         try {             ws.send(text);         } catch (exception) {             alert(exception.description);         }     } </script>  <body onload="startsocket()"> <div id="status"></div> <div id="stock"></div> <button onclick="send();">left!</button> </body> </html> 

if second page created first , given name , both on same domain, can access scripts in second page using name.

its same passing information iframe containing webpage. security prevents working if 2 pages in different domains target of xss attacks.

dc

in example there no communication between pages. comment see trying implement chat system. no cannot talk each other.

sorry thought both pages hosted in same browser.

when connect server.php not connecting same script twice connecting 2 independant copies of same script. unless work in server php message , return no message passed

also default server.php disconnect after 30 seconds. need disable that.

what trying more complicated seem realise

dc


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -