943,814 Members | Top Members by Rank

Ad:
Apr 21st, 2006
0

Random CSS

Expand Post »
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 <style> tag, but it does not work. :evil: When I go to "view source", I don't see the line that suppously was written by the JS function.

PLEASE HELP!!:-|
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jiruiz78 is offline Offline
10 posts
since Apr 2006
Apr 21st, 2006
0

Re: Random CSS

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 <HEAD> section of your page.

Give us a link?
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Apr 22nd, 2006
0

Re: Random CSS

Quote ...
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.
Reputation Points: 14
Solved Threads: 1
Junior Poster in Training
Esopo is offline Offline
50 posts
since Feb 2006
Apr 22nd, 2006
0

Re: Random CSS

Quote ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Tribolis is offline Offline
21 posts
since Apr 2006
Apr 23rd, 2006
0

Re: Random CSS

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).
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jiruiz78 is offline Offline
10 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Text Not Showing up in IE, Fine in Firefox * NS
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: how do i change fore color in a textbox with javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC