User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Nov 2006
Posts: 3
Reputation: Sisil is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Sisil Sisil is offline Offline
Newbie Poster

Random CSS Stylesheet selector exists?

  #1  
Nov 21st, 2006
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 "
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Random CSS Stylesheet selector exists?

  #2  
Nov 21st, 2006
JavaScript is not well-suited to this task. You need to use a server-side language to render the style sheet link dynamically.
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Solution Re: Random CSS Stylesheet selector exists?

  #3  
Nov 26th, 2006
Hi there,

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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:19 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC