Javascript-who can tell mac.pcbeta.com about the website skin change function?

Source: Internet
Author: User
I always wanted to implement mac.pcbeta.com's skin function. Recently, I wrote a javascript code to save the skin name set by the user to localstorage. Every time I refresh the page, I call the field stored in localstorage, then reference the CSS file contained in the new skin according to the field .... I always wanted to implement mac.pcbeta.com's skin function.
Recently, I wrote a javascript code to save the skin name set by the user to localstorage. Every time I refresh the page, I call the field stored in localstorage, reference the CSS file contained in the new skin based on the field.
However, after writing the script, I found that, even though it can be implemented, the user needs to execute this script every time during refresh. Will it consume a lot of resources?
In fact, resource consumption is a trivial matter. The most important thing is that before the script is run, the webpage skin is the default one, and no new CSS files are introduced, but the webpage interface changes only after the script is executed.

In this way, each time you refresh the page, a highlighted white screen will appear. (The default skin is white, and the skin is set to another color), very uncomfortable.

So how does mac.pcbeta.com implement it?

I see that every time they change their skin, they will refresh the page and submit one? Styleid = 34. Then the server obtains this styleid and inserts it with the backend script? How to implement it? You must specify the visitor's skin.

Reply content:

I always wanted to implement mac.pcbeta.com's skin function.
Recently, I wrote a javascript code to save the skin name set by the user to localstorage. Every time I refresh the page, I call the field stored in localstorage, reference the CSS file contained in the new skin based on the field.
However, after writing the script, I found that, even though it can be implemented, the user needs to execute this script every time during refresh. Will it consume a lot of resources?
In fact, resource consumption is a trivial matter. The most important thing is that before the script is run, the webpage skin is the default one, and no new CSS files are introduced, but the webpage interface changes only after the script is executed.

In this way, each time you refresh the page, a highlighted white screen will appear. (The default skin is white, and the skin is set to another color), very uncomfortable.

So how does mac.pcbeta.com implement it?

I see that every time they change their skin, they will refresh the page and submit one? Styleid = 34. Then the server obtains this styleid and inserts it with the backend script? How to implement it? You must specify the visitor's skin.

You can write it like this

if styleid="black"
 elseif styleid="red"
 else
 

Or

styleid = isset(styleid) ? styleid : 'common';
 

However, mac.pcbeta.com also needs to jump pages .. Some browsers will also be white ..

Capture this website,
1. Run index. php. get parameter styleid = 29
2. Get the specified js and css and corresponding images.

The page is refreshed, that is, the parameter judgment in the index. php file. The parameter corresponds to different css and js variables.

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.