2012-08-03 27 views
0

我打算利用websockets製作一個特定領域的聊天工具。到目前爲止,我有此代碼:Javascript window.postmessage()幫助 - 不明白用法

<!doctype html> 
<html> 
<head> 
    <title>Chatroom Dev Stage</title> 
    <script type="text/javascript"> 
     function submit(form) { 
    var win=document.getElementbyId(iframe).contentWindow 
    win.postmessage(form.msg.value, 
<body> 
<h3>Conversation:</h3> 
<iframe height="150px" width="300px" id="iframe"></iframe> 
<br> 
<form name="sendmsg"> 
    <input type="text" id="msg"></input> 
    <button onclick="submit()">Send</button> 
</form> 
</body> 
</html> 

它創建一個iframe,它將顯示對話中的消息。 <input> messagebox將是用戶輸入消息的地方。這將完全基於客戶端,並且不會被附加或訪問服務器。

問題: 我不明白如何通過網絡將消息發送到另一臺計算機(命令的語法,IP地址等)以及如何使用命令window.postmessage()。 P - 作爲一個新用戶,是否有人可以告訴我,如果需要的話,我可以改善我的問題,詢問道德,以防它不好?

+0

即時規劃運行在本地wifi上,而不是在網絡上。這將在我的工作場所運行,我只會連接到無線網絡。 – Progrmr 2012-08-03 06:59:59

回答