1
2
3
Print Test4
5
6
7 /*div#ctlDiv {height:750px;width:50%;float:left;border-style:solid;border-color:red;border-width:0px;}*/
8 div#pdfDiv{height:750px;width:49%;border-style:solid;border-color:red;border-width:0px;}
9
10
11
12 varsocket;13
14 window.οnlοad= functionload()15 {16
17 document.getElementById("pdfDiv").style.visibility="hidden";18 }19
20 functionsetStatusLabel(msg)21 {22 vareStatus=document.getElementById("connectionStatus");23 eStatus.innerHTML=msg;24 }25
26 functiondoConnect(callback)27 {28 varserviceUrl=document.getElementById("serviceUrl").value;29
30 socket= newWebSocket(serviceUrl);31
32 //监听消息
33 socket.onmessage= function(event)34 {35 console.log('Client received a message',event);36 document.getElementById("pdfDiv").style.visibility="hidden";37 //parse json
38 varobj=eval('('+event.data+')');39
40 if(obj&&(obj.previewURL||obj.previewImage))41 {42 varurl;43 if(obj&&obj.previewURL) {44 url=obj.previewURL;45 }else if(obj&&obj.previewImage) {46 url=obj.previewImage;47 }48 varpdf=document.getElementById('pdf');49 if(pdf) {50 pdf.setAttribute('src', url);51 document.getElementById("pdfDiv").style.visibility="visible";52 }53 }54 varresultElement=document.getElementById("resultMessage");55 resultElement.value=resultElement.value+event.data+ "\n";56 resultElement.scrollTop=resultElement.scrollHeight;57 };58
59 socket.onopen= function(event)60 {61 if(callback!= null) {62 callback();63 }64 setStatusLabel("已连接");65 }66
67 socket.οnerrοr= function(error)68 {69 console.log("Failed to connect CN print at" +serviceUrl, error);70 setStatusLabel("连接错误");71 }72
73 //监听Socket的关闭
74 socket.onclose= function(event)75 {76 console.log('Client notified socket has closed',event);77 setStatusLabel("连接关闭");78 };79 }80
81 functionsendCommand()82 {83 if(typeofsocket== "undefined" ||socket.readyState==WebSocket.CLOSED) {84 doConnect(sendCommand);85 return;86 }87
88 if(socket.readyState!=WebSocket.OPEN) {89 alert("无效连接:" +socket.readyState);90 return;91 }92
93 varmsg=document.getElementById('printmessage').value;94 varrepeatCount=document.getElementById('repeatCount').value;95 varisPreview=document.getElementById('isPreview').checked;96 vartime= newDate().getTime();97
98 for(varindex= 0; index
101 if(obj["task"])102 {103 //taskID
104 obj["task"]["taskID"]=time.toString()+ "_TASK_" +index;105
106 //preview
107 obj["task"]["preview"]=isPreview;108 }109
110 varnewMsg=JSON.stringify(obj);111 socket.send(newMsg);112 }113 }114
115 functionclearResult()116 {117 varresultElement=document.getElementById("resultMessage");118 resultElement.value= "";119 }120
121
122
123
124
125
126
127
128
129 重复发送请求:
130 预览模式131
132
133 未知
134
135
136 {137 "cmd": "print",138 "requestID": "123458976",139 "version": "1.0",140 "task": {141 "taskID": "7293666",142 "preview": false,143 "printer": "",144 "notifyMode": "allInOne",145 "previewType": "html",146 "documents": [147 {148 "documentID": "0123456789",149 "contents": [150 {$list}//数据是在这里哦接收的,你不需要改什么,如果你觉得这不是你想要的,你也可以借鉴一下方法151 ]152 }153 ]154 }155 }156
157
158
159
160
161
162