<!DOCTYPE HTML> <html> <head> <basehref="<%=basePath%>"> <!-- Bootstrap --> <linkrel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script> <![endif]--> <scripttype="text/javascript"charset="utf-8"src="<%=path%>/ueditor/ueditor.config.js"></script> <scripttype="text/javascript"charset="utf-8"src="<%=path%>/ueditor/ueditor.all.min.js"></script> <!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败--> <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文--> <scripttype="text/javascript"charset="utf-8"src="<%=path%>/ueditor/lang/zh-cn/zh-cn.js"></script>
<scripttype="text/javascript"> var ue = UE.getEditor('editor'); var websocket = null; //判断当前浏览器是否支持WebSocket if ('WebSocket'inwindow) { websocket = newWebSocket("ws://192.168.0.102:8080/ssm/websocket"); } else { alert("对不起!你的浏览器不支持webSocket") } //连接发生错误的回调方法 websocket.onerror = function () { setMessageInnerHTML("error"); }; //连接成功建立的回调方法 websocket.onopen = function (event) { setMessageInnerHTML("加入连接"); }; //接收到消息的回调方法 websocket.onmessage = function (event) { setMessageInnerHTML(event.data); }; //连接关闭的回调方法 websocket.onclose = function () { setMessageInnerHTML("断开连接"); }; //监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接, // 防止连接还没断开就关闭窗口,server端会抛异常。 window.onbeforeunload = function () { var is = confirm("确定关闭窗口?"); if (is){ websocket.close(); } }; //将消息显示在网页上 functionsetMessageInnerHTML(innerHTML) { $("#msg").append(innerHTML+"<br/>") }; //关闭连接 functioncloseWebSocket() { websocket.close(); } //发送消息 functionsend() { var message = $("#text").val() ; websocket.send(message); $("#text").val("") ; } functionsendMsg(){ var msg = ue.getContent(); websocket.send(msg); ue.setContent(''); } </script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <scriptsrc="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <scriptsrc="http://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <scripttype="text/javascript"src="<%=path%>/js/Globals.js"></script> <scripttype="text/javascript"src="<%=path%>/js/websocket.js"></script> </html>