Ajax chat. js files used on the Internet

Source: Internet
Author: User
Tags sendmsg ajax chat

Var xmlHttp = false;
Var ichatstate;
Try {
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e2 ){
XmlHttp = false;
}
}
If (! XmlHttp & typeof XMLHttpRequest! = 'Undefined '){
XmlHttp = new XMLHttpRequest ();
}

Function sendmsg (){
Var msgbody = escape (document. getElementById ("msgbody"). value );
Var sendto = escape (document. getElementById ("sendto"). value );
Var SendData = "msgbody =" + msgbody + "& sendto =" + sendto;
XmlHttp. open ("POST", "../ichat/sendmsg. asp", false );
XmlHttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
XmlHttp. onreadystatechange = function sendok () {if (xmlHttp. readyState = 4 ){}}
XmlHttp. send (SendData );
Document. getElementById ("msgbody"). value = "";
Showmsg ();
}

Function hot_key (){

If (window. event. keyCode = 13 & window. event. ctrlKey & document. getElementById ("msgbody"). value! = "") {Sendmsg ();}

}

Function exitchat (){
Var url = "../ichat/online. asp? Action = exit & pid = "+ Math. random ();
XmlHttp. open ("GET", url, true );
XmlHttp. send (null );
}

Function compute chat (){
Window. ionline. location. href = "../ichat/online. asp? Action = WeChat chat ";
Showmsg ();
}

Function showonline (){
Var url = "../ichat/online. asp? Action = showonline & pid = "+ Math. random ();
XmlHttp. open ("GET", url, true );
XmlHttp. send (null );
}

Function showmsg (){
Var url = "../ichat/getmsg. asp? Pid = "+ Math. random ();
XmlHttp. open ("GET", url, true );
XmlHttp. onreadystatechange = reloadX;
XmlHttp. send (null );
}

Function reloadX (){
If (xmlHttp. readyState = 4 ){
Var response = xmlHttp. responseText;
Document. getElementById ("mymsg"). innerHTML = response;
Document. getElementById ("mymsg"). scrollTop = document. getElementById ("mymsg"). scrollHeight;
SetTimeout ("showmsg ();", 10000 );
}
}

Function saveset (){
Var mycolor = document. getElementById ("mycolor"). value;
Var msgtotal = document. getElementById ("msgtotal"). value;
Var mystate = document. getElementById ("mystate"). value;
Var allowmsg = document. getElementById ("allowmsg"). value;
Var closemsg;

If (document. getElementById ("closemsg"). checked ){
Closemsg = document. getElementById ("closemsg"). value;
} Else {
Closemsg = "off ";
}
Var SendData = "mycolor =" + mycolor + "& msgtotal =" + msgtotal + "& mystate =" + mystate + "& allowmsg =" + allowmsg + "& closemsg =" + closemsg;
XmlHttp. open ("POST", "../ichat/chatset. asp", false );
XmlHttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
XmlHttp. onreadystatechange = function sendok () {if (xmlHttp. readyState = 4 ){
Alert ('set saved ')
If (ichatstate = "open") {window. location. reload ();}
}}
XmlHttp. send (SendData );

Showmsg ();
Document. getElementById ('layer _ ichatset'). style. display = 'none ';

}

Function openichat (){
Ichatstate = "open"
}

Function closeichat (){
Ichatstate = "close"
}

Function showonlineuser (){
Document. getElementById ('layer _ online'). style. display = 'block ';

Var url = "../ichat/showonline. asp? Pid = "+ Math. random ();
XmlHttp. open ("GET", url, true );
XmlHttp. onreadystatechange = reloadX2;
XmlHttp. send (null );

}

Function reloadX2 (){
If (xmlHttp. readyState = 4 ){
Var response = xmlHttp. responseText;
Document. getElementById ("onlineuser"). innerHTML = response;
}
}

Function readset (){
Document. getElementById ('layer _ ichatset'). style. display = 'block ';

Var url = "../ichat/myset. asp? Pid = "+ Math. random ();
XmlHttp. open ("GET", url, true );
XmlHttp. onreadystatechange = showset;
XmlHttp. send (null );

}

Function showset (){
If (xmlHttp. readyState = 4 ){
Var response = xmlHttp. responseText;
Document. getElementById ("setplan"). innerHTML = response;
}
}

Function setsendto (username ){
If (username = "all "){
Document. getElementById ("sendto"). value = '';
Document. getElementById ("talkwith"). innerHTML = 'all Member ';
} Else {
Document. getElementById ("sendto"). value = username;
Document. getElementById ("talkwith"). innerHTML = username;
}
Var url = "../ichat/checkuser. asp? User = "+ escape (username) +" & pid = "+ Math. random ();
XmlHttp. open ("GET", url, true );
XmlHttp. onreadystatechange = showtips;
XmlHttp. send (null );
}

Function showtips (){
If (xmlHttp. readyState = 4 ){
Var response = xmlHttp. responseText;
Document. getElementById ("userstate"). innerHTML = response;
}
}

Function clearlog (){

If (window. confirm ("are you sure you want to clear all chat records? ") = True)
{
Var url = "../ichat/clearlog. asp? Pid = "+ Math. random ();
XmlHttp. open ("GET", url, true );
XmlHttp. send (null );
}

}

Var ichatwinstate
Ichatwinstate = "max ";

Function min ()
{
Ichatwinstate = (ichatwinstate = "max ")? "Min": "max"

If (ichatwinstate = "min "){
Document. getElementById ('mbody'). style. display = 'none ';
Document. getElementById ('myichat'). height = parseInt (document. getElementById ('ichat _ title'). height );
Document. getElementById ('myichat '). style. top = document. body. clientHeight-parseInt (document. getElementById ("ichat_title "). style. height) + document. body. scrollTop;
} Else {
Document. getElementById ('mbody'). style. display = 'block ';
Iresize ();
}
}

Function closeit (){
Document. getElementById ('myichat'). style. display = 'none ';
}

Function iresize (){
If (ichatwinstate = "min "){
Document. getElementById ('myichat '). style. top = document. body. clientHeight-parseInt (document. getElementById ("ichat_title "). style. height) + document. body. scrollTop-1;
} Else {
Document. getElementById ('myichat '). style. top = document. body. clientHeight + document. body. scrollTop-parseInt (document. getElementById ("mbody "). style. height)-85;
}
}

Var ey = 0, ex = 0, lx = 0, ly = 0, canDrg = false, thiso = null;
Var x, y, rw, rh;

Function dargit (o, e) // Main function
{
Thiso = o;
CanDrg = true;
If (! Document. all)
{
Lx = e. clientX; ly = e. clientY;
}
Else
{
Lx = event. x; ly = event. y;
}
If (document. all) thiso. setCapture ();
Try {}
Catch (e ){}
St (o); // set to the front or back

}
Document. onmousemove = function (e)
{
If (! Document. all) {x = e. clientX; y = e. clientY;} else {x = event. x; y = event. y ;}
If (canDrg)
{
Var ofsx = x-lx;
Thiso. style. left = parseInt (thiso. style. left) + ofsx;
Lx = x;
Var ofsy = y-ly;
Thiso. style. top = parseInt (thiso. style. top) + ofsy;
Ly = y;

// Display data in the status bar
// Window. status = thiso. style. left + "left: top" + thiso. style. top + "rh: rw" + rh + "+" + rw;
}
}

Document. onmouseup = function ()
{
CanDrg = false; // set the drag variable to false.
Try {}
Catch (e ){}
If (document. all & thiso! = Null)
{
// Capture the image in ie;
Thiso. releaseCapture ();
Thiso = null;
}
}

Function st (o)
{

Var p = o. parentNode;
If (p. lastChild! = O)
{
P. appendChild (o );
}
If (rh <= 20 & rw >= 160)
{
CanDrg = false;

If (rw <1, 180)
{
// Set the closing area; // comment out the area if not needed;
// Alert ("close ");
P. removeChild (o)
// RemoveChild (this );

}
Else
{
Window. status = rw + "|" + rh;
If (p. firstChild = o) return;
P. insertBefore (o, p. firstChild );
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.