Collected online ajax chat.js file _javascript tips

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 Intochat () {
Window.ionline.location.href= ". /ichat/online.asp?action=intochat ";
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=" + allowms G + "&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 has been 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== "everyone") {
document.getElementById ("SendTo"). Value = ';
document.getElementById ("Talkwith"). InnerHTML = ' all Members ';
}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 erase 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 functions
{
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);//before or after placement

}
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;

Status bar displays data
window.status=thiso.style.left+ "Left:top" +thiso.style.top+ "RH:RW" +rh+ "+" +RW;
}
}

Document.onmouseup=function ()
{
candrg=false;//drag variable set to False
try{}
catch (e) {}
if (document.all && thiso!= null)
{
IE, will be clear capture;
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<180)
{
Set the closing area;//If you do not need to be able to comment out;
Alert ("Off");
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.