Case study of JavaScript skin style Switching

Source: Internet
Author: User
Not long ago, I made a script for page skin switching and encountered a very difficult problem. There were three style files, namely, the first line of the two files had a line of import url(default.css For the import sentence, and the sample format was black.css.
<LINK rel = stylesheet type = text/CSS src = "black.css"/>
Introduce to the page and write the switching code in the beginning.

Document. stylesheets [0]. href = "blue.css ";

Normally in IE6, in IE7/8beta1, the ult.css pattern is lost, but the style defined by blue.css is successfully applied. In Firefox, the style cannot be executed at all. therefore, after referring to some compatibility methods, add an ID to the link label and name it lkstyle, that is
<Link id = "lkstyle" rel = "stylesheet" type = "text/CSS" href = "black.css"/>
The modified script is as follows:

VaR objstyle = Document. getelementbyid ("lkstyle ");
Objstyle. href = "";
Objstyle. href = "blue.css ";

These three codes can be run in Firefox/IE6/IE7/ie8beta, and the imported import style will not be lost during the switch.

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.