Two-level domain name steering class _javascript skills

Source: Internet
Author: User
Domainclass.js
/*
@Class DomainClass (two-level domain name steering Class)
@author Carefree Cloud-http://bbs.51js.com
@Version 1.0
@Date 2006-11-2
Please keep this information @Rights if used, thank you
*/

function DomainClass () {
Record itself
Varōwner=this;
Domain Name Collection
var arr=[];
Exposing properties
Set default directory
Owner.defaultdir= "";
Set Default domain name
Owner.defaultdomain= "";
Set default Jump URL
Owner.defaulturl= "";
Nonexistent domain jump
Owner.noexisturl= "";
Exposing methods
Add a domain name method
Parameter 1: Domain 2: Directory 3: Output domain 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 a 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 array
}
Find a domain name
function Seekdomain (href_loc) {
Get level Two 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
}
}
Domain name objects processed when not in existence
var notobj=new Object ();
Notobj.out=owner.defaultdomain;
Notobj.dir=owner.defaultdir;
Notobj.url=owner.noexisturl;
Alert ("hint: \ n \ nyou have not set a domain name: \" "+loc+" \ ")! ");
Header substitution
Href_loc=href_loc.replace (/\/\/[^.) +/, "//" +notobj.out);
Jumpweb (Href_loc,notobj);
}

Jump function
function Jumpweb (href_loc,obj) {
Decision Jump
if (obj.url!= "") {
Self.location=obj.url;
Return
}
Replace the airspace name with default
if (obj.out== "") {
Obj.out=owner.defaultdomain;
}
Domain substitution
Href_loc=href_loc.replace (/\/\/[^.) +/, "//" +obj.out);
Replace empty directory as default
if (obj.dir== "") {
Obj.dir=owner.defaultdir;
}
Directory substitution
Href_loc=href_loc.replace (/(\/\/[^\/]+\/)/, "$" +obj.dir+ "\/");
Redefining URLs
Self.location=href_loc;
}
initialization, exposing
Owner.init=function () {
If you set the default jump
if (owner.defaulturl!= "") {
Self.location=owner.defaulturl;
Return
}
If no default directory or Default 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īpt language= "javascrīpt" src= "Leon/code/javascrīpt/domainclass.js" ></scrīpt>
</HEAD>

<BODY>
<scrīpt language= "Javascrīpt" >
<!--
var d=new domainclass ();
/*
DefaultDir: Default Jump Directory
Defaulturl: Default all jump directory, such as set this, all requests will be the main
DefaultDomain: Default output domain name
Noexisturl: The default does not have this URL of the jump, such as set this, all no URL to the jump to the main, if not the default

Adddomain: Add a domain name method, at least one parameter, otherwise depending on the invalid

*/
Set the default directory
d.defaultdir= "Pal";
Set Default jump
D.defaulturl= "Http://hi.baidu.com/pallove";
Set Default output domain name
d.defaultdomain= "Pal";
Add level two 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īpt>
</BODY>
</HTML>

Detailed effects please view
URL Jump
Carefree Blog Http://51js.pallove.net
Baidu Space Http://baidu.pallove.net
Directory Jump
http://pal.pallove.net/
Http://love.pallove.net
Http://flash.pallove.net

In this beta above code download this type of file
Http://pal.pallove.net/leon/code/javascrīpt/domainclass.js

If you use or reprint, please retain the copyright and personal information. Thank you!

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.