954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Random CSS

Hello there, I need my page to randomly select a CSS document. I don't want the user to select it, but instead to do it when the page loads.
This is the script I have so far:

<script language="javascript" type="text/javascript">
var ranNum= Math.floor(Math.random()*3+1);
document.write("<link rel='stylesheet' href='hd"+ranNum+".css' type='text/css'>");
</script>

This function does write the proper

jiruiz78
Newbie Poster
10 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

The "document.write" statement is deprecated in most new doctypes.

However, with a loose (or no) doctype, this should work. Where is the script running? It needs to run in the section of your page.

Give us a link?

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 
When I go to "view source", I don't see the line that suppously was written by the JS function.


You don't usually get to see the line that was written, since it happens on the client. The "view source" option gives you the original source, not the client-execution result.

Esopo
Junior Poster in Training
50 posts since Feb 2006
Reputation Points: 14
Solved Threads: 1
 
I need my page to randomly select a CSS document. I don't want the user to select it, but instead to do it when the page loads.


Is that mean skin chooser? For user selects the CSS style and reload the page.

Tribolis
Newbie Poster
23 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

Me again, sorry for the late response, it was the weekend.
I don't want the user to select the a CSS and then refresh the page. I want to do that for them.

The way I have setup my page is that I have one CSS for the whole page: styles.CSS, and then I have 3 other CSS documents (hd1.css, hd2.css, hd3.css) that I want to use them in the document randomly.

Here is the page
http://www.arch.usyd.edu.au/~jrui0688/template.htm

(this is the testing page).

jiruiz78
Newbie Poster
10 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You