📄 guest.js
字号:
//支持CTRL+ENTER发信息
function ctrlEnter()
{
if(!window.event.ctrlKey && window.event.keyCode==13)
{
document.getElementById("SendBtn").onclick();
return false;
}
}
var interval;
function OpenLogin()
{
Opt.Show('<div id="chatcon2"><div class="cont"><table><col width="83" /><col/><tr><td><img src="images/user.gif" alt=""/> Name:</td><td><input id="Name" type="text" name="" class="inpt"/></td></tr><tr><td><img src="images/email.gif" alt=""/> Email:</td><td><input type="text" id="Email" class="inpt"/></td></tr><tr><td><img src="images/lightbulb.gif" alt=""/> Service:</td><td> <select id="AskType"></select></td></tr><tr><td colspan="2" class="tc"><input onclick="guest.Login();" type="image" src="images/Ebtn_in.gif"/></td></tr></table></div></div>',493,250);
guest.LoadProblem();
}
function Guest()
{
window.onbeforeunload=this.LoginOut;
}
Guest.prototype.Name="";
Guest.prototype.Email="";
Guest.prototype.AskType="";
/*
登录,异步POST
*/
Guest.prototype.Login=function()
{
this.Name=encodeURI(document.getElementById("Name").value);
if(this.Name.trim().length==0){Msg.Show(guestEN.login[1],1) ;return;}
if(!/^[\w\. ]{2,20}$/ig.test(this.name)){Msg.Show(guestEN.name,1) ;return;}
this.Email=encodeURI(document.getElementById("Email").value);
if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/ig.test(this.Email)){Msg.Show(guestEN.email,1);return;}
this.AskType=document.getElementById("AskType").value;
var data='Opt=new&name='+this.Name+'&email='+this.Email+"&AskType="+this.AskType;
document.getElementById('SP_Name').innerHTML=document.getElementById("Name").value;
document.getElementById('SP_Email').innerHTML=document.getElementById("Email").value;
Opt.Close();
Msg.Show(guestEN.waiting);
Msg.Func='OpenLogin()';
executPost(data,'GuestChat.aspx',true,'guest.EndLogin');
}
Guest.prototype.Worker='';
/*
登录结果,界面操作
*/
Guest.prototype.EndLogin=function()
{
if(xmlHttp.readyState!=4)return;
var re=xmlHttp.status;
switch(re)
{
case 800:
//该用户在线
interval=setInterval(guest.GetData,1000);//从服务器读工作者交流信息
Msg.Func=null;
guest.Worker=xmlHttp.responseText;
document.getElementById('ShowArea').insertBefore(createElement('div',null,null,guestEN.WELCOME.replace('##',guest.Worker)),document.getElementById("EndShow"));
Msg.Close();
break;
case 801:
//没有客服在线
Msg.timeClose(guestEN.login[0],3);
break;
default:
Msg.timeClose(xmlHttp.responseText,3);
break;
}
}
Guest.prototype.GetData=function()
{
executPost("Opt=GetResult",'GuestChat.aspx',true,'guest.MsgEnd');
//var msg=eval(xmlHttp.responseText);
// for(var i=0;i<msg[1].length;i++)
// {
// var showMessage="<span class='GuestName'>"+msg[0]+"</span> <span class='ShowTime'>"+new Date()+"</span><br /><span class='textcont'>"+msg[1][i].replace(/⊕/g,"'"+"</span>");
// document.getElementById('ShowArea').insertBefore(createElement('div',null,null,showMessage),document.getElementById("EndShow"));
// }
// if(msg[1].length>0)document.getElementById("EndShow").scrollIntoView();
}
Guest.prototype.ShowMsg=function(xml)
{
var msg=eval(xml);
for(var i=0;i<msg[1].length;i++)
{
var showMessage="<span class='GuestName'>"+msg[0]+"</span> <span class='ShowTime'>"+new Date()+"</span><br /><span class='textcont'>"+msg[1][i].replace(/⊕/g,"'"+"</span>");
document.getElementById('ShowArea').insertBefore(createElement('div',null,null,showMessage),document.getElementById("EndShow"));
}
if(msg[1].length>0)document.getElementById("EndShow").scrollIntoView();
}
/*
退出
*/
Guest.prototype.LoginOut=function()
{
executPost("Opt=LoginOut",'GuestChat.aspx',true,'guest.EndLoginOut');
}
Guest.prototype.EndLoginOut=function()
{
if(xmlHttp.readyState!=4)return;
clearInterval(interval);
//访问者点退出
//Msg.timeClose(guestEN.UserClose,3);
Msg.Show(guestEN.UserClose);
}
/*
添加客户问题
*/
Guest.prototype.LoadProblem=function()
{
var doc=XmlDocument("CustServiceType.xml");
var n=doc.getElementsByTagName("Item");
for(var i=0;i<n.length;i++)
{
document.getElementById("AskType").options[i]=new Option(n[i].childNodes[0].data,n[i].getAttribute("Value"));
}
}
/*
发送信息
*/
Guest.prototype.Msg=function()
{
if($('Input').value.trim()=="")return;
var showMessage="<span class='MyName'>"+this.Name+"</span> <span class='ShowTime'>"+new Date()+"</span><br /><span class='Showinput'>"+$('Input').value.replace(/\n/g,"</span><br /><span class='Showinput'>");
document.getElementById('ShowArea').insertBefore(createElement('div',null,null,showMessage),document.getElementById("EndShow"));
document.getElementById("EndShow").scrollIntoView();
var data="Opt=SendAsk&Message="+$('Input').value.replace(/\n/g,"<br />").replace(/\r/g,"");
//var data="Opt=SendAsk&Message="+$('Input').value.replace(/\n/g,"").replace(/\r/g,"");
executPost(data,'GuestChat.aspx',true,'guest.MsgEnd');
$('Input').value="";
}
Guest.prototype.MsgEnd=function()
{
if(xmlHttp.readyState!=4)return;
var re=xmlHttp.status;
switch(re)
{
case 801:
//该用户在线
Msg.timeClose(guestEN.login[2],1);
break;
case 803:
guest.SecondLogin();
break;
case 804:
guest.ShowMsg(xmlHttp.responseText);
break;
case 805:
//客户断开
//Msg.Show(guestEN.UserClose);
alert(guestEN.UserClose);
window.location.reload();
break;
}
}
Guest.prototype.Out=function()
{
this.LoginOut();
}
/*
二次登录
*/
Guest.prototype.SecondLogin=function()
{
var data='Opt=new&name='+this.Name+'&email='+this.Email+"&AskType="+this.AskType;
executPost(data,'GuestChat.aspx',true,'guest.EndLogin');
}
var guest;
var getGuestMsg;
function loadGuest()
{
guest=new Guest();
OpenLogin();
}
window.onload=loadGuest;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -