DomainClass. js
/*
@ Class DomainClass (second-level domain name conversion Class)
@ Author Xiaoyao cloud-http://bbs.51js.com
@ Version 1.0
@ Date 2006-11-2
@ Rights keep this information if you use it. Thank you.
*/
Function DomainClass (){
// Record itself
Var writable wner = this;
// Domain name set
Var arr = [];
/// // Public attributes
// Set the default directory
Owner. defaultDir = "";
// Set the default domain name
Owner. defaultDomain = "";
// Set the default redirect URL
Owner. defaultURL = "";
// Jump to a nonexistent Domain Name
Owner. noExistURL = "";
/// // Public Method
// Add domain name Method
// Parameter 1: domain name 2: Directory 3: Output domain name 4: Specify the jump address
Owner. addDomain = function (){
If (arguments. length = 0 ){
Return;
}
If (arguments. length> 0 ){
Var tempObj = new Object ();
TempObj. domain = arguments [0]; // domain Name
TempObj. dir = ""; // corresponding directory
TempObj. out = ""; // output Domain Name
TempObj. url = ""; // specify the jump address
}
If (arguments. length> 1 ){
TempObj. dir = arguments [1];
}
If (arguments. length> 2 ){
TempObj. out = arguments [2];
}
If (arguments. length> 3 ){
TempObj. url = arguments [3];
}
Arr. push (tempObj); // push to the array
}
// Search for domain names
Function seekDomain (href_loc ){
// Obtain the second-level domain name header
Var loc = href_loc.split ("//") [1]. split (".") [0];
For (var I = 0; I <arr. length; I ++ ){
// Determine the Domain Name
If (arr [I]. domain = loc ){
// Jump
JumpWeb (href_loc, arr [I]);
Return;
}
}
// The domain name object to be processed if it does not exist
Var notObj = new Object ();
NotObj. out = owner. defaultDomain;
NotObj. dir = owner. defaultDir;
NotObj. url = owner. noExistURL;
Alert ("prompt: \ n you have not set a domain name like \" + loc +! ");
// Domain name header replacement
Href_loc = href_loc.replace (// \/[^.] +/, "//" + notObj. out );
JumpWeb (href_loc, notObj );
}
// Jump function
Function jumpWeb (href_loc, obj ){
// Determine the jump
If (obj. url! = ""){
Self. location = obj. url;
Return;
}
// Replace the default airspace name
If (obj. out = ""){
Obj. out = owner. defaultDomain;
}
// Domain name replacement
Href_loc = href_loc.replace (// \/[^.] +/, "//" + obj. out );
// Replace the empty directory with the default
If (obj. dir = ""){
Obj. dir = owner. defaultDir;
}
// Directory replacement
Href_loc = href_loc.replace (/(\/[^ \/] + \/)/, "$1" + obj. dir + "\/");
// Redefine the URL
Self. location = href_loc;
}
// Initialize and publish
Owner. init = function (){
// If the default redirect is set
If (owner. defaultURL! = ""){
Self. location = owner. defaultURL;
Return;
}
// If no default directory or domain name is set
If (owner. defaultDir = "" | owner. defaultDomain = ""){
Alert ("Please set: \ n \ n1. default directory: DomainClass. defaultDir. \ n \ n2. default domain name: DomainClass. defaultDomain ");
}
Else {
SeekDomain (self. location. href );
}
}
}
Index.htm
<HTML>
<HEAD>
<TITLE> Loading... </TITLE>
<Scr limit pt LANGUAGE = "Limit Cr limit pt" src = "leon/code/Revoke Cr limit pt/domainclass. js"> </scr limit pt>
</HEAD>
<BODY>
<Scr limit pt LANGUAGE = "Limit Cr limit pt">
<! --
Var d = new DomainClass ();
/*
DefaultDir: Default jump directory
DefaultURL: by default, all redirect directories are redirected. If this option is set, all requests are directed to this directory.
DefaultDomain: Default output Domain Name
NoExistURL
AddDomain: The method for adding a domain name. There is at least one parameter. Otherwise, it is invalid.
*/
// Set the default directory
D. defaultDir = "pal ";
// Set the default redirect
// D. defaultURL = "http://hi.baidu.com/pallove ";
// Set the default output Domain Name
D. defaultDomain = "pal ";
// Add a second-level domain name
D. addDomain ("pal", "pal", "pal ");
D. addDomain ("blog", "blog", "pal ");
D. addDomain ("leon", "leon", "love ");
D. addDomain ("51js", "51js", "51js", "http://www.51js.com/11191 ");
D. addDomain ("baidu", "http://hi.baidu.com/pallove ");
D. init ();
// -->
</Scr platinum pt>
</BODY>
</HTML>
For more information, see
URL jump out
Carefree and carefree Blog http://51js.pallove.net
Baidu space co http://baidu.pallove.net
Directory jump
Http://pal.pallove.net/
Http://love.pallove.net
Http://flash.pallove.net
Download such files from the above Code
Http://pal.pallove.net/leon/code/javascrw.pt/domainclass.js
If you use or reprint it, Please retain the copyright and personal information. Thank you!