Automatically select China Netcom Telecom server

Source: Internet
Author: User
<! -- Automatically select China Telecom Netcom Code -->
// Select the fastest way to access the site China Telecom Network

var cookietest = "tel";
var urlnew;
var urltop;
var k = 1;
var topall;
var tourlcnc
var tourltel
var tophref = top. location. href;
urlnew = tophref. split (". ");
topall = urlnew. length; // address length
If (urlnew [0]. indexof (1) =-1) {
urltop = urlnew [0] + k;
for (k = 1; k <= Topall-1; k ++)
{< br> urltop = urltop + ". "+ urlnew [k]; // obtain Netcom's actual redirection address with 1
}< BR >}< br> else
{< br> urltop = replaceall (urlnew [0], "1", "");
for (k = 1; k <= Topall-1; k ++)
{
urltop = urltop + ". "+ urlnew [k]; // obtain the actual China Telecom switch address Band 1
}< BR >}

function getcookie (name)
{< br> var Arg = Name + "=";
var Alen = Arg. length;
var clen = document. cookie. length;
var I = 0;
while (I var J = I + Alen;
If (document. cookie. substring (I, j)
== Arg)
return getcookieval (j);
I = document. cookie. indexof ("", I) + 1;
if (I = 0) break;
}< br> return NULL;
}

Function getcookieval (offset ){
VaR endstr = Document. Cookie. indexof (";", offset );
If (endstr =-1) // no other elements are specified
Endstr = Document. Cookie. length;
Return Unescape (document. Cookie. substring (offset, endstr ));
}

// Obtain the current cookie
Function get ()
{
VaR cookiearea = getcookie ('user _ Region ');
Alert (cookiearea );
If (cookiearea = "CNC" & cookietest! = "CNC ")
{Alert ("SDF ");
This. Location = urltop; // if y has a cookie, it will directly go to China Netcom.
}
Else
{
// Determine the telecom line
If (cookiearea = "tel" & cookietest! = "Tel ")
{
This. Location = urltop; // if y has cookies, direct access to China Telecom
}
}
}

Function setcnc ()
{
VaR mydate = new date ();
Mydate. settime (mydate. gettime () + 315360000000 );
Document. Cookie = "user_area = CNC; expires =" + mydate. togmtstring () + "; domain = 127.0.0.1"; // set the next Automatic Login of cookies to China Netcom
Get ();
}
Function settel ()
{
VaR mydate = new date ();
Mydate. settime (mydate. gettime () + 315360000000 );
Document. Cookie = "user_area = Tel; expires =" + mydate. togmtstring () + "; domain = 127.0.0.1"; // set the next Automatic Login of cookies to China Telecom
Get ();
}

var cookiearea = getcookie ('user _ Region');
If (cookiearea = NULL) {
document. writeln ("");
document. writeln ("")
}< br> else
{< br> get ();
}

Function replaceall (text, replacement, target ){
If (text = NULL | text = "") return text; // If text has no content, return text
If (replacement = NULL | replacement = "") return text; // if replacement has no content, return text
If (target = NULL) target = ""; // if the target has no content, set it to an empty string.
VaR returnstring = ""; // defines the return value variable and initializes it.
VaR Index = text. indexof (replacement); // defines the index subscript of the replacement query and performs the first search.
While (index! =-1)
{// Until no replacement is found, or perform the following processing:
Returnstring + = text. substring (0, index) + target; // if there are characters before the replacement, add them to the return value, and add the target
TEXT = text. substring (index + replacement. Length); // remove the replacement and the character of the front edge.
Index = text. indexof (replacement); // query and prepare for next Processing
}
If (text! = "") Returnstring + = text; // If a character is found after the last replacement, It is accumulated into the return value.
Return returnstring; // return
}

<! -- Over -->

The above code is the judgment Code placed on the homepage of the Telecom station. Netcom is similar to this one. Just replace cookietest. Of course, you can also combine the two. If you are interested, you can try them out or discuss them together.

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.