function init() {
  if (typeof(Debugger) == 'function') {
    oDbg = new Debugger(2,'simpleclient');
    oDbg.start();
  } else {
    // if you're using firebug or safari, use this for debugging
    oDbg = new JSJaCConsoleLogger(2);
    // comment in above and remove comments below if you don't need debugging
//     oDbg = function() {};
//     oDbg.log = function() {};
  }
  try { // try to resume a session
    if (JSJaCCookie.read('btype').getValue() == 'binding')
      con = new JSJaCHttpBindingConnection({'oDbg':oDbg});
    else
      con = new JSJaCHttpPollingConnection({'oDbg':oDbg});    con.registerHandler('message',handleMessage);
    con.registerHandler('presence',handlePresence);
    con.registerHandler('iq',handleIQ);
    con.registerHandler('onerror',handleError);
    con.registerHandler('onStatusChanged',handleStatusChanged);
    con.registerHandler('ondisconnect', handleDisconnected);    if (con.resume()) {      document.getElementById('login_pane').style.display = 'none';
      document.getElementById('sendmsg_pane').style.display = '';
      document.getElementById('err').innerHTML = '';    }
  } catch (e) {} // reading cookie failed - never mind}
onload = init;onerror = function(e) { 
  document.getElementById('err').innerHTML = e;   document.getElementById('login_pane').style.display = '';
  document.getElementById('sendmsg_pane').style.display = 'none';  if (con && con.connected())
    con.disconnect();
  return false; 
};onunload = function() {
  if (typeof(con) != 'undefined') {
  // save backend type
    if (con._hold) // must be binding
      (new JSJaCCookie('btype','binding')).write();
    else
      (new JSJaCCookie('btype','polling')).write();
    if (con.suspend) 
      con.suspend(); 
  }
};// ]]>
    </script>
    <style type="text/css">
/*<![CDATA[*/
body {
font-family: "Bitstream Vera Sans", "Verdana", sans;
font-size: 0.8em;
margin: 12px;
}
h2 {
border-bottom: 1px solid grey;
}
input {
border: 1px solid grey;
}
#iResp {
width: 420px;
height: 260px;
overflow: auto;
border: 2px dashed grey;
padding: 4px;
}
#msgArea {
width: 420px;
height: 45px;
padding: 4px;
margin: 0;
border: 2px dashed grey;
}
.spaced {
margin-bottom: 4px;
}
.msg {
border-bottom: 1px solid black;
}
.error {
font-weight: bold;
color: red;
}
/*]]>*/
    </style>
  </head>
  <body>
  <h1><a href="">JSJaC Simple Client</a></h1>  <div id="err"></div>  <div id="login_pane">
    <h2>Login</h2>
    <form name="loginForm" onSubmit="return doLogin(this);" action="#">
      <table>
<tr><th>Backend Type</th><td><input type="radio" name="backend" value="binding" id="backend1" tabindex="1"/> <label for="backend1">HTTP Binding</label><br /> <input type="radio" name="backend" value="polling" id="backend2" tabindex="2"/> <label for="backend2">HTTP Polling</label></td></tr>
<tr><th><label for="http_base">HTTP Base</label></th><td><input type="text" name="http_base" id="http_base" tabindex="3"/></td></tr>
        <tr><th colspan="2"><hr noshade size="1"/></th></tr>
<tr><th><label for="server">Jabber Server</label></th><td><input type="text" name="server" id="server" tabindex="4"/></td></tr>
<tr><th><label for="username">Username</label></th><td><input type="text" name="username" id="username" tabindex="5"/></td></tr>
<tr><th><label for="password">Password</label></th><td><input type="password" name="password" id="password" tabindex="6" /></td></tr>
<tr><th></th><td><input type="checkbox" name="register" id="register_checkbox" /> <label for="register_checkbox">Register new account</label></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" value="Login" tabindex="7"></td></tr>
     </table>
    </form>
  </div>  <div id="sendmsg_pane" style="display:none;">
    <h2>Incoming:</h2>
    <div id="iResp"></div>
    <h2>Send Message</h2>
      <form name="sendForm" onSubmit="return sendMsg(this);" action="#">
<div class="spaced"><b>To:</b> <input type="text" name="sendTo" tabindex="1"></div>
<div class="spaced"><textarea name="msg" id='msgArea' rows="3" cols="80" tabindex="2"></textarea></div>
<div class="spaced"><input type="submit" value="Send" tabindex="3"> * <input type="button" value="Quit" tabindex="4" onclick="return quit();"></div>
      </form>
    </div>
  </body>
</html>
(完)

解决方案 »

  1.   

    这里用到一个jsjac的js文件,可以从
    http://zeank.in-berlin.de/jsjac
    去下载jsjac 的1.0版本,带有document,上面的文件就是jsjac的一个使用例子,叫simpleclient.html,级别不够,所以只能放100分,不一定要全写注释,会哪里就写一点就可以了,谢谢各位大侠
      

  2.   

    init
    1 初始化一些东西
       调用 setupCon ,绑定一些消息处理函数,那些 handle xxx 就是被绑定用于处理服务器返回数据的。
    2 判断是否登录过,如果是就隐藏登录界面,显示发送消息界面。
    登录界面中登录按钮触发 doLogin,用于登录
    消息界面中发送按钮触发 sendMsg,用于发送消息。