📄 message.html
字号:
<html>
<head>
<object width="0" height="0"
classid="CLSID:C348XXXX-A7F8-11D1-AA75-00C04FA34D72"
codebase="#VERSION=2,0,0,0">
</object>
<object id="AgentControl" width="0" height="0"
classid="CLSID:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F"
codebase="#VERSION=2,0,0,0">
</object>
<object width="0" height="0"
classid="CLSID:B8F2846E-CE36-11D0-AC83-00C04FD97575"
codebase="#VERSION=6,0,0,0">
</object>
<script language="javascript" src= "agent.js"></script>
<script language="javascript" src="msagent.js"></script>
<script language="javascript">
var request;
var datasize;
var lastMsgID;
var chat;
var xmlDoc;
var agentArray = new Array();
var timer = null;
var myName;
var myAgent;
var pop = null;
function unload() {
if (window.XMLHttpRequest)
{// code for all new browsers
request=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
request=new ActiveXObject("Microsoft.XMLHTTP");
}
//request = new ActiveXObject("Microsoft.XMLHTTP");
request.open("POST", "logout.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(null);
if (myName.length >0){
chat = document.getElementById("chatObj");
chat.parentNode.removeChild(chat);
alert("Good Bye!");
}
}
function loadMsg() {
myName = document.getElementById("username").getAttribute("value");
if (myName.length > 0) {
datasize = 0;
lastMsgID = 0;
chat = document.getElementById("chatObj");
chat.SetVariable("online", true);
getUpdate();
checkFlashActivity();
} else {
timer = setTimeout("loadMsg()", 100);
}
}
function getUpdate() {
var params = "datasize=" + datasize;
if (window.XMLHttpRequest)
{// code for all new browsers
request=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
request=new ActiveXObject("Microsoft.XMLHTTP");
}
//request = new ActiveXObject("Microsoft.XMLHTTP");
request.onreadystatechange = stateChange;
request.open("POST", "server.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(params);
}
function stateChange() {
if (request.readyState == 4 && request.status == 200 && request.responseText) {
try {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
// need to change the above line if using ie7
xmlDoc.loadXML(request.responseText);
} catch (e) {
var parser = new DOMParser();
xmlDoc=parser.parseFromString(request.responseText, "text/xml");
}
datasize = request.responseText.length;
updateChat();
addAgent();
delAgent();
getUpdate();
}
}
function updateChat() {
var messages = xmlDoc.getElementsByTagName("message");
var msgStr = "";
// create a string for the messages
for(i=lastMsgID; i<messages.length;i++){
var msg = messages.item(i);
msgStr += "|" + msg.getAttribute("name");
msgStr += "|" + msg.getAttribute("file");
if(msg.firstChild != null) {
content = msg.firstChild.nodeValue;
}
msgStr += "|" + content;
}
lastMsgID = messages.length;
if(msgStr.length > 0) {
chat.SetVariable("newMessage", msgStr + "|");
if (msg.getAttribute("file") == "")
read(msg.getAttribute("name"), content);
}
}
function addAgent() {
var users = xmlDoc.getElementsByTagName("user");
// check child nodes of the 'users' node with the agent array
for (i=0; i< users.length; i++) {
var exist = false
var name = users[i].getAttribute("name");
var agentname = users[i].getAttribute("agent")
// check all items in the agentArray
/** add your code here **/
for (j=0; j<agentArray.length;j++){
if(agentArray[j] == null) continue;
if(agentArray[j].username == name) {
exist = true;
break;
}
}
// if there is a new user
if (!exist) {
// add the information about the user's agent to the array
// and show the agent
/** add your code here **/
var agent = new Agent(name, agentname);
agentArray.push(agent);
agent.Show();
if(name == myName)
myAgent = agent;
}
}
}
function delAgent() {
var users = xmlDoc.getElementsByTagName("user");
var msg = "";
for (i=0; i< agentArray.length; i++) {
var exist = false
for (j=0; j< users.length; j++) {
if (agentArray[i] == null) continue;
if (agentArray[i].username == users[j].getAttribute("name")) {
exist = true;
break;
}
}
if (!exist && agentArray[i] != null) {
agentArray[i].Hide();
agentArray[i].Unload();
agentArray[i] = null;
}
}
}
function delAllAgent() {
for (i=0; i< agentArray.length ; i++) {
if (agentArray[i] != null) {
agentArray[i].Hide();
agentArray[i].Unload();
agentArray[i] = null;
}
}
}
function speech() {
// ask Ms Agent to read out the message
/** add your code here **/
var msg = chat.GetVariable("speechMsg");
if (msg.length != 0) {
chat.SetVariable("speechMsg", "");
myAgent.Speak(msg);
}
}
function read(name, msg) {
for (i=0; i< agentArray.length; i++ ) {
if (agentArray[i] == null) continue;
if (agentArray[i].username == name) {
agentArray[i].Speak(msg);
break;
}
}
}
function openFile() {
// open an uploaded file
/*** add your code here ***/
var file = chat.GetVariable("openFile");
if (file.length != 0) {
chat.SetVariable("openFile", "");
pop = window.open(file, "pop", "width=500,height=500,resizable=1,scrollbars=1");
}
}
function sendWhiteboard() {
var wbMsg = chat.GetVariable("wbMsg");
if (wbMsg != "") {
chat.SetVariable("wbMsg", "");
var params = "username=" + myName + "&wb=" + wbMsg + "&message=__EMPTY__";
if (window.XMLHttpRequest)
{// code for all new browsers
wbRequest=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
wbRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
//wbRequest = new ActiveXObject("Microsoft.XMLHTTP");
wbRequest.open("POST", "process_whiteboard.php", true);
wbRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
wbRequest.send(params);
}
}
function checkFlashActivity() {
speech();
openFile();
sendWhiteboard();
timer = setTimeout("checkFlashActivity()", 100);
}
</script>
</head>
<body bgcolor="#000000" onload="loadMsg()" onunload="unload()" >
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"
id="chatObj" width="800" height="350">
<param name="movie" value="chat.swf">
<param name="quality" value="high">
<param name="play" value="false">
<embed play="false" swliveconnect="true" id="chatEmbed" name="chatEmbed" src="chat.swf"
quality="high" width="800" height="400" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</embed></object><br />
<input type="hidden" value="" id="username" />
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -