A good common. js script _ javascript technique for online applications

Source: Internet
Author: User
A good common. js script for online applications var iconwar = "";
Var iconload = "";
Var badstr = "! & ^ # | % $) (-+ /? <> @'~ ';: {} [], = \".\\";
Var badsql = "! & ^ | + /? <> '~ '= ";
Var $ show = function (e) {try {document. getElementById (e). style. display = "" ;}catch (e ){}};
Var $ hide = function (e) {try {document. getElementById (e). style. display = "none" ;}catch (e ){}};
Var $ W = document. write;
Var reurl, js_UserName;
Reurl = document. referrer;
If (reurl = "")
{
Reurl = "/index.html ";
}
Function onDisplay (id ){
If (document. getElementById (id). style. display = 'None '){
$ Show (id );
}
Else {
$ Hide (id );
}
}
Function onLabelTxt (id, LabelID, ShowTxt, HideTxt ){
If (document. getElementById (id). style. display = 'None '){
$ Show (id );
Document. getElementById (LabelID). value = HideTxt;
}
Else {
$ Hide (id );
Document. getElementById (LabelID). value = ShowTxt;
}
}
Function listdisp (tid, lid ){
If (document. getElementById (tid). style. display = 'None '){
$ Show (tid );
}
Else {
$ Hide (tid );
}

If (lid = 'T1 '){
Return 'T1 _ off ';
}
Else if (lid = 't2 '){
Return 't2 _ off ';
}
Else if (lid = 'T1 _ off '){
Return 't1 ';
}
Else if (lid = 't2 _ off '){
Return 't2 ';
}

}

Function trim (str ){
Return (str + ''). replace (/(\ s +) $/g,''). replace (/^ \ s +/g ,'');
}

Function addbookmark (url, site ){
If (is_ie ){
Window. external. addFavorite (url, site );
} Else {
Alert ('Please press "Ctrl + D" to add bookmark ');
}
}

// AJAX_START
Var xmlhttp = null;
Function createxmlhttp (){
Try {
Xmlhttp = new ActiveXObject ("Msxml2.xmlhttp ");
}
Catch (e ){
Try {
Xmlhttp = new ActiveXObject ("Microsoft. xmlhttp ");
}
Catch (oc ){
Xmlhttp = null;
}
}
If (! Xmlhttp & typeof XMLHttpRequest! = "Undefined "){
Xmlhttp = new XMLHttpRequest ();
}

If (! Xmlhttp ){
Alert ("your browser does not support AJAX features. Some functions on this page will not work properly! ");
}
}


// Js cookies operation function *********************

Function delcookie (name ){
Setcookie (name ,"");
}

Function getcookie (name ){
Var cookie_start = document. cookie. indexOf (name );
Var cookie_end = document. cookie. indexOf (";", cookie_start );
Return cookie_start =-1? '': Unescape (document. cookie. substring (cookie_start + name. length + 1, (cookie_end> cookie_start? Cookie_end: document. cookie. length )));
}

Function setcookie (cookieName, cookieValue, seconds ){
Var expires = new Date ();
Var path = "/";
Var domain = "alixixi.com ";
Var secure = "";
Expires. setTime (expires. getTime () + seconds );
Document. cookie = escape (cookieName) + '=' + escape (cookieValue)
+ (Expires? '; Expires =' + expires. toGMTString ():'')
+ (Path? '; Path =' + path :'/')
+ (Domain? '; Domain =' + domain :'')
+ (Secure? '; Secure ':'');
}

// GetQueryString ***********************
Var locstringinclustring({{doc ument. location. href );
Function GetQueryString (str ){
Var rs = new RegExp ("(^ |)" + str + "= ([^ \ &] *) (\ & | $ )", "gi" cmd.exe c (LocString), tmp;
If (tmp = rs) return tmp [2];
Return "";
}

// VScroll displays the title ************************
Function _ ge (a) {return document. getElementById? Document. getElementById (a): null ;}
Function VScroll (){

Var m_box = null;
Var m_lineHeight = 0;
Var m_lineNum = 0;
Var m_splitStr = '';
Var m_speed = 0;
Var m_delay = 0;

Var m_pos = 0;
Var m_stopTimes = 0;
Var m_stop = false;

This. init = function (box, lnum, lheight, speed, delay, split ){
M_box = _ ge (box );
M_lineNum = lnum;
M_lineHeight = lheight;
M_speed = speed;
M_delay = delay;
M_splitStr = split;
}

This. play = function (){

If (m_stop ){
Return;
}
M_pos = m_box.scrollTop;
If (m_pos % m_lineHeight = 0 & m_stopTimes <m_delay & m_box.scrollTop <m_lineHeight * m_lineNum ){
M_stopTimes ++;
} Else {
M_box.scrollTop ++;
If (m_pos % m_lineHeight = 0 & m_stopTimes> = m_delay ){
M_stopTimes = 0;
}
}
If (m_box.scrollTop> m_lineHeight * m_lineNum ){
M_box.scrollTop = 0;
}
}

This. show = function (){
SetInterval (m_self + ". play ()", m_speed );
}
This. setSelf = function (n ){
M_self = n;
}
This. stop = function (n ){
M_stop = n;
}

}

Function show_date (){

Var today = new Date ();
Var day = new Array ();
Var str = '';

Day [0] = "day ";
Day [1] = "1 ";
Day [2] = "2 ";
Day [3] = "3 ";
Day [4] = "4 ";
Day [5] = "5 ";
Day [6] = "6 ";

Str + = today. getFullYear ();
Str + = "year ";
Str + = today. getMonth () + 1;
Str + = "month ";
Str + = today. getDate ();
Str + = "day ";
Str + = "";
Str + = "Week ";
Str + = day [today. getDay ()];

Return str;
}


Function ajaxPost (url, stateurl, data, info, loading ){
Var url, stateurl, data, info, loading
Createxmlhttp ();
If (data = "" | data = null)
{
// GetMode
Xmlhttp. open ("get", url, true );
Xmlhttp. setRequestHeader ("CONTENT-TYPE", "application/x-www-form-urlencoded ");
Xmlhttp. onreadystatechange = function () {checkState (stateurl, info, loading );};
Xmlhttp. send (null );
}
Else
{
// PostMode
Xmlhttp. open ("post", url, true ,"","");
Xmlhttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
Xmlhttp. onreadystatechange = function () {checkState (stateurl, info, loading );}
Xmlhttp. send (data );
}
}


Function checkState (stateurl, info, loadnews ){
If (xmlhttp. readyState = 4 ){
Document. getElementById (info). innerHTML = loadnews;
If (xmlhttp. status = 200 ){
Var retext = xmlhttp. responseText. split ("$ ");
Document. getElementById (info). innerHTML = retext [1];
Switch (retext [0]) {
Case "usreg": if (stateurl! = "") Location. href = stateurl;
Break;
Case "uslogin": if (stateurl! = "") Location. href = stateurl;
Break;
Case "active": location. href = retext [2];
Break;
Case "errinfo": return false;
Break;
Default: document. getElementById (info). innerHTML = retext [0];
}
}
}
Else {
Document. getElementById (info). innerHTML = loadnews;
}
}

// AJAX_END


// Run the code
Function runEx (cod1 ){
Cod = document. getElementById (cod1)
Var code = cod. value;
If (code! = ""){
Var newwin = window. open ('','','');
Newwin. opener = null
Newwin.doc ument. write (code );
Newwin.doc ument. close ();
}
}
//
Function doCopy2 (ID ){
If (document. all ){
TextRange = document. getElementById (ID). createTextRange ();
TextRange.exe cCommand ("Copy ");
Alert ('copied successfully ');
}
Else {
Alert ("this function is only valid on IE ")
}
}
//
Function doCopy (obj ){
Var rng = document. body. createTextRange ();
Rng. moveToElementText (obj );
Rng. scrollIntoView ();
Rng. select ();
Rng.exe cCommand ("Copy ");
Rng. collapse (false );
}

Function doCopyUrl ()
{
Document. getElementById ("CopyUrl"). value = parent. location. href;
Document. getElementById ("CopyUrl"). select ();
Document.exe cCommand ("copy ");
Alert ("the URL is successfully copied to the clipboard! ")
}

// Save another code
Function doSave (obj ){
Var winname = window. open ('', '_ blank', 'top = 10000 ');
Winname.doc ument. open ('text/html ', 'replace ');
Winname.doc ument. writeln (obj. value );
Winname.document.execcommand('saveas', '', 'code.htm ');
Winname. close ();
}

Function findobj (n, d ){
Var p, I, x;
If (! D) d = document;
If (p = n. indexOf ("? ")> 0 & parent. frames. length ){
D = parent. frames [n. substring (p + 1100000000.doc ument;
N = n. substring (0, p );
}
If (x! = D [n] & d. all) x = d. all [n];
For (I = 0 ;! X & I <d. forms. length; I ++) x = d. forms [I] [n];
For (I = 0 ;! X & d. layers & I <d. layers. length; I ++) x = findobj (n, d.layerspolici#.doc ument );
If (! X & document. getElementById) x = document. getElementById (n );
Return x;
}
Function submitonce (theform ){
// If IE 4 + or NS 6 +
If (document. all | document. getElementById ){
// Screen thru every element in the form, and hunt down "submit" and "reset"
For (I = 0; I Var tempobj = theform. elements [I]
If (tempobj. type. toLowerCase () = "submit" | tempobj. type. toLowerCase () = "reset ")
// Disable em
Tempobj. disabled = true
}
}
}
Function openScript (url, width, height ){
Var Win = window. open (url, "openScript", 'width = '+ width +', height = '+ height +', resizable = 1, scrollbars = yes, menubar = no, status = yes ');
}

Function CheckAll (form ){
For (var I = 0; I Var e = form. elements [I];
If (e. name! = 'Chkall') e. checked = form. chkall. checked;
}
}

Function chkuserlogin (){
If (getcookie ('userid') = ''| getcookie ('userid') = 0 | getcookie ('username') = ''){
Return false;
}
Else {
Return true;
}
}

Function chkcookieed (){
If (getcookie ("username ")! = ""){
Var url = "/ajax. asp? Action = loginmenu ";
Url + = "& random =" + Math. random ();
AjaxPost (url, null, null, "top_login ","");
}
}


Function userlogout (){
Var url = "/AspCode. asp? GetType = logout ";
Url + = "& random =" + Math. random ();
AjaxPost (url, null, null, "top_login", "exiting ...");
Chkcookieed ();
Alert ('Welcome to the Alibaba West WEB development community again ...');
}

// Decrypt the Cookie
Function DecodeCookie (str)
{
Var strArr;
Var strRtn = "";
StrArr = str. split ("");
Try {
For (var I = strArr. length-1; I> = 0; I --)
StrRtn + = String. fromCharCode (eval (strArr [I]);
} Catch (e ){
}
Return strRtn;
}

Function isnumber (str ){
Var digits = "1234567890 ";
Var I = 0;
Var strlen = str. length;
While (I Var char = str. charAt (I );
If (digits. indexOf (char) =-1) return false; I ++;
}
Return true;
}

// Check for invalid characters
// Str characters to be checked
// Invalid badwords characters & | <> =
Function checkbadwords (str, badwords ){
If (typeof (str )! = "String" | typeof (badwords )! = "String "){
Return (false );
}
For (I = 0; I Bad = badwords. charAt (I );
For (j = 0; j If (bad = str. charAt (j )){
Return false;
Break;
}
}
}
Return true;
}

Function switchTag (tag, bar)
{
For (I = 1; I <6; I ++)
{
If ("tag" + I = tag)
{
Document. getElementById (tag). getElementsByTagName ("a") [0]. className = "selectli" + I;
Document. getElementById (tag). getElementsByTagName ("a") [0]. getElementsByTagName ("span") [0]. className = "selectspan" + I;
} Else {
Document. getElementById ("tag" + I). getElementsByTagName ("a") [0]. className = "";
Document. getElementById ("tag" + I). getElementsByTagName ("a") [0]. getElementsByTagName ("span") [0]. className = "";
}
If ("bar" + I = bar)
{
Document. getElementById (bar). className = "";
} Else {
Document. getElementById ("bar" + I). className = "hidebar ";
}
Document. getElementById ("bar"). className = bar;
}
}
Function switchNew (fornum, showname, lname, newid)
{
For (I = 1; I <fornum; I ++)
{
If (lname + I = newid)
{
Document. getElementById (newid). className = showname;
} Else {
Document. getElementById (lname + I). className = "hidebar ";
}
}
}

Function bgc (cssid ){
Switch (cssid ){
Case 0: this. style. background = '# ffff ';
Break;
Case 1: this. style. background = '# E8F5FE ';
Break;
Case 2: this. style. background = '# ffffdd ';
Break;
Case 3: this. style. background = '# f2fddb ';
Break;
Case 4: this. style. background = '# FFE7F4 ';
Break;
Case 5: this. style. background = '# F7F7F7 ';
Break;
Default: this. style. background = '# ffff ';
}
}

Function imgzoom (o ){
If (event. ctrlKey ){
Var zoom = parseInt (o. style. zoom, 10) || 100;
Zoom-= event. wheelDelta/12;
If (zoom> 0 ){
O. style. zoom = zoom + '% ';
}
Return false;
} Else {
Return true;
}
}
Function CheckAll (form)
{
For (var I = 0; I {
Var e = form. elements [I];
If (e. Name! = "ChkAll" & e. disabled! = True)
E. checked = form. chkAll. checked;
}
}

Function addfav (favtitle, favform, favid)
{
Location. href = "http://www.alixixi.com/account/user_Favorites.asp? Url = "+ document. URL +" & favtitle = "+ favtitle +" & from = "+ favform +" & id = "+ favid;
}

Function mto (aid ){
Location. href = "http://www.alixixi.com/account/user_post.asp? Aid = "+ aid;
}

Function apost (url ){
Createxmlhttp ();
// GetMode
Url + = "& random =" + Math. random ();
Xmlhttp. open ("get", url, true );
Xmlhttp. setRequestHeader ("CONTENT-TYPE", "application/x-www-form-urlencoded ");
// Xmlhttp. onreadystatechange = function () {checkSeo ();};
Xmlhttp. send (null );
}

Function checkSeo (){
Var info = 'test ';
Var loadnews = 'loading ';
If (xmlhttp. readyState = 4 ){
Document. getElementById (info). innerHTML = loadnews;
If (xmlhttp. status = 200 ){
Var retext = xmlhttp. responseText;
Document. getElementById (info). innerHTML = retext;
}
}
Else {
Document. getElementById (info). innerHTML = loadnews;
}
}
Function setstyle (sid ){
If (sid! = ''| Sid! = Null)
{
Switch (parseInt (sid ))
{
Case 1:
Setcookie ('Ali _ Styles', 1, 600000 );
Document.all.css. href = '/css/style1.css ';
Break;
Case 2:
Setcookie ('Ali _ style', 2, 600000 );
Document.all.css. href = '/css/style2.css ';
Break;
Case 3:
Setcookie ('Ali _ style', 3, 600000 );
Document.all.css. href = '/css/style3.css ';
Break;
}
}
}
Function ResumeError (){
Return true;
}
Window. onerror = ResumeError;
Setstyle (getcookie ('Ali _ style '));
// Window. onload = setstyle (getcookie ('Ali _ style '));

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.