•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 397,809 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,524 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2137 | Replies: 2
![]() |
•
•
Join Date: Nov 2006
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
m looking for a Javascript function or similar which will automatically load a different stylesheet randomly each time a page is visited.
I have found several which work on user selection, or on browser size. My Javscript coding isn't up to adapting them sad
If anyone knows of an example, I'd appreciate the knowledge. It's just so that the user goes "Ohooh "
I have found several which work on user selection, or on browser size. My Javscript coding isn't up to adapting them sad
If anyone knows of an example, I'd appreciate the knowledge. It's just so that the user goes "Ohooh "
Hi there,
first i am agree with tgreer,
well but you can use JavaScript to do this functionality,
here the is Code:
page.html :
randomCss.js :
example :http://www.katarey.com/downloads/randomCss/
I hope this will useful or you!
Best Regards,
Rahul Dev
first i am agree with tgreer,
well but you can use JavaScript to do this functionality,
here the is Code:
page.html :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Random Css Using Javascript</title>
<script language="JavaScript" type="text/javascript" src="randomCss.js"></script>
</head>
<body>
<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td height="153"><div align="center">StyleSheet Will change on every reload of this page</div></td>
<td><div align="center">To view effect Press F5 </div></td>
</tr>
</table>
</body>
</html>randomCss.js :
function get_randomCssNum()
{
var ranCssNum= Math.floor(Math.random()*5);
//var ranCssNum= Math.floor(Math.random()*Number of CSS you Have);
return ranCssNum;
}
function getaCss()
{
var whichCss=get_randomCssNum();
var cssName=new Array(5)
// var cssName=new Array(Number of CSS you Have)
cssName[0]="<link rel='stylesheet' type='text/css' href='a.css'>";
cssName[1]="<link rel='stylesheet' type='text/css' href='b.css'>";
cssName[2]="<link rel='stylesheet' type='text/css' href='c.css'>";
cssName[3]="<link rel='stylesheet' type='text/css' href='d.css'>";
cssName[4]="<link rel='stylesheet' type='text/css' href='e.css'>";
//I am using 5 CSS files in this example. you can add or remove ;)
//for Add more CSS just add line like this
//cssName[Next Number]="<link rel='stylesheet' type='text/css' href='CSS FILE URL'>";
return cssName[whichCss]
}
document.write(getaCss());example :http://www.katarey.com/downloads/randomCss/
I hope this will useful or you!
Best Regards,
Rahul Dev
Freelance Web Designer & Developer
Http//www.Katarey.com
Http//www.Katarey.com
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- centring an image in a css stylesheet (HTML and CSS)
- CSS stylesheet layout (HTML and CSS)
- CSS – Imagemap - Highlight Item (HTML and CSS)
- Random CSS (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Can't put 2 Javasript working in the same page!
- Next Thread: javaScript/XHTML.



Linear Mode