How to implement cross-site style switching through webcss _ javascript tips-js tutorial

Source: Internet
Author: User
Css allows you to easily switch the entire site style. If you need a friend, you can refer to it and hope to help you paste the Code directly.

The Code is as follows:


// Use two $ elements to avoid conflict with jquery.
Function $ (s ){
Return document. getElementById (s );
}
Function setblue (){
// Write cookie first
// WriteCookie ("ISCSSSTYLE", "css/CRM_blue.css? 1.1.23 ", 365, true );
// Set a new css file
$ ("Maincss"). href = "css/CRM_blue.css? 1.1.23 ";
// Retrieve the main frame page and reset the css file
// Var childobj = maid parent.doc ument. getElementById ("ManagerMain"). contentWindow;
// Childobj.doc ument. getElementById ("maincss"). href = "css/CRM_blue.css? 1.1.23 ";
}
Function setgreen (){
// Write cookie first
// WriteCookie ("ISCSSSTYLE", "css/CRM.css? 1.1.23 ", 365, true );
// Set a new css file
$ ('Maincss '). href = "css/CRM.css? 1.1.23 ";
// Retrieve the main frame page and reset the css file
// Var childobj = maid parent.doc ument. getElementById ("ManagerMain"). contentWindow;
// Childobj.doc ument. getElementById ("maincss"). href = "css/CRM.css? 1.1.23 ";
}
Function setgray (){
// Write cookie first
// WriteCookie ("ISCSSSTYLE", "css/CRM_gray.css? 1.1.23 ", 365, true );
// Set a new css file
$ ('Maincss '). href = "css/CRM_gray.css? 1.1.23 ";
// Retrieve the main frame page and reset the css file
// Var childobj = maid parent.doc ument. getElementById ("ManagerMain"). contentWindow;
// Childobj.doc ument. getElementById ("maincss"). href = "css/CRM_gray.css? 1.1.23 ";
}


Function setActiveStyleSheet (title ){
// Var I, a, main;
// For (I = 0; (a = document. getElementsByTagName ("link") [I]); I ++)
//{
// If (a. getAttribute ("rel"). indexOf ("style ")! =-1 & a. getAttribute ("title "))
//{
// A. disabled = true;
// If (a. getAttribute ("title") = title)
// A. disabled = false;
//}
//}
// $ ("Maincss"). attr ("href", "css/CRM_blue.css? 1.1.23 ");
// $ ('Maincss '). href = "css/CRM_blue.css? 1.1.23 ";
// Set the css file
$ ('Maincss '). href = title;
}
Function getActiveStyleSheet (){
// Var I,;
// For (I = 0; (a = document. getElementsByTagName ("link") [I]); I ++)
//{
// If (a. getAttribute ("rel"). indexOf ("style ")! =-1 &&
// A. getAttribute ("title ")&&! A. disabled)
// Return a. getAttribute ("title ");
//}
// Return null;
Var cssfile =$ $ ('maincss '). href;
// Alert (cssfile );
Return cssfile;
}
Function getPreferredStyleSheet (){
// Var I,;
// For (I = 0; (a = document. getElementsByTagName ("link") [I]); I ++)
//{
// If (a. getAttribute ("rel"). indexOf ("style ")! =-1
// & A. getAttribute ("rel"). indexOf ("alt") =-1
// & A. getAttribute ("title "))
// Return a. getAttribute ("title ");
//}
// Return null;
Var cssfile =$ $ ('maincss '). href;
// Alert (cssfile );
Return cssfile;
}
Function createCookie (name, value, days ){
If (days ){
Var date = new Date ();
Date. setTime (date. getTime () + (days * 24x60*60*1000 ));
Var expires = "; expires =" + date. toGMTString ();
}
Else
Expires = "";
Document. cookie = name + "=" + value + expires + "; path = /";


}
Function writeCookie (name, value, hours, escp ){
Var expire = "";
If (hours! = Null ){
Expire = new Date (). getTime () + hours * 3600000 );
Expire = "; expires =" + expire. toGMTString ();
}
If (escp = "True "){
Document. cookie = name + "=" + value + expire;
} Else {
Document. cookie = name + "=" + escape (value) + expire;
}
}


Function readCookie (name ){
Var nameEQ = name + "= ";


Var ca = document. cookie. split (';');


For (var I = 0; I <ca. length; I ++ ){
Var c = ca [I];


While (c. charAt (0) = '')
C = c. substring (1, c. length );
If (c. indexOf (nameEQ) = 0)
Return c. substring (nameEQ. length, c. length );
}
Return null;
}
$ (Document). ready (function (){


// Var title = readCookie ("ISCSSSTYLE ");
// Var title = "css/CRM_blue.css? 1.1.23 ";


// If (title! = Null & title! = "Undefined "){
// SetActiveStyleSheet (title );
//}
});

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.