JS version website style switch instance code _ javascript skills

Source: Internet
Author: User
In addition to the memory function, you can also set the retention time for this website style switch. For example, the default style sheet is automatically restored after 5-180 days. Style table connection, set three styles, and write the image background you want to change to the style table.

The Code is as follows:






The first is the default style table.
Script -- Author: dynamicdrive.com
Protocol of use: http://www.dynamicdrive.com/notice.htm

The Code is as follows:


// Style Sheet Switcher version 1.0 Nov 9th, 2005
// Author: Dynamic Drive: http://www.dynamicdrive.com
// Usage terms: http://www.dynamicdrive.com/notice.htm
Function getCookie (Name ){
Var re = new RegExp (Name + "= [^;] +", "I"); // construct RE to search for target name/value pair
If (document. cookie. match (re) // if cookie found
Return document. cookie. match (re) [0]. split ("=") [1] // return its value
Return null
}
Function setCookie (name, value, days ){
Var expireDate = new Date ()
// Set "expstring" to either future or past date, to set or delete cookie, respectively
Var expstring = (typeof days! = "Undefined ")? ExpireDate. setDate (expireDate. getDate () + parseInt (days): expireDate. setDate (expireDate. getDate ()-5)
Document. cookie = name + "=" + value + "; expires =" + expireDate. toGMTString () + "; path = /";
}
Function deleteCookie (name ){
SetCookie (name, "moot ")
}
Function setStylesheet (title ){
Var I, cacheobj
For (I = 0; (cacheobj = document. getElementsByTagName ("link") [I]); I ++ ){
If (cacheobj. getAttribute ("rel"). indexOf ("style ")! =-1 & cacheobj. getAttribute ("title ")){
Cacheobj. disabled = true
If (cacheobj. getAttribute ("title") = title)
Cacheobj. disabled = false // enable chosen style sheet
}
}
}
Function chooseStyle (styletitle, days ){
If (document. getElementById ){
SetStylesheet (styletitle)
SetCookie ("mysheet", styletitle, days)
}
}
Var selectedtitle = getCookie ("mysheet ")
If (document. getElementById & selectedtitle! = Null) // load user chosen style sheet if there is one stored
SetStylesheet (selectedtitle)


Call Method

The Code is as follows:


Default Style
Orange Style
Blue


Note: The title content should be changed to the name of your style sheet. Here, it is set to 5 days.

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.