Click to See Complete Forum and Search --> : Is there a way to use js to load a url within a cell of a normal html table??


MattchuB
12-03-2003, 05:43 PM
I'm new to Javascript but I want to know if there is a way to load a web page within a cell of a normal html table. I want to randomize it but I only want it to change once a week. Is there any way I can do this??

I know that I can randomize a picture in a cell, and I suppose if all else fails, I make my pages into images and randomize them that way, but I'd still like to have them change once a week rather than every time the page is loaded.

Any help will be much appreciated. I know nothing about writing scripts, I just find them and copy them. Thanks.

batfink
12-03-2003, 06:38 PM
You'll get the idea with this code, although I have only made it choose a random site on Sundays only. For all other days it defaults to google.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>::: By Batfink :::</title>
<script language="javascript">
function whatday()
{
var today=new Date(),neWurl = new Array(),i;
neWurl[0]="http://www.google.co.uk";
neWurl[1]="http://www.altavista.co.uk";
neWurl[2]="http://www.yahoo.co.uk";
theday=today.getDay();
if(theday==0) // if today is Sunday
{
document.getElementById("myurl").src=neWurl[Math.floor(Math.random()*3)];
}
}
</script>
</head>
<body onLoad="whatday()">
<table border="1">
<tr><td>cooeewl</td></tr>
<tr><td width="200"><iframe id="myurl" src="http://www.google.co.uk"></iframe></td></tr>
<tr><td>This is a table</td></tr></table>
</body>
</html>

MattchuB
12-03-2003, 08:43 PM
Hey thanks, I'll try that and let you know if it works or not.

MattchuB
12-04-2003, 02:31 AM
Actually, is there a way to make it change only on sunday and stay the same until next sunday? I'd really like it to change once a week only. If not, can you make one that changes once a day?

batfink
12-04-2003, 07:51 AM
This code changes the site once a week but not randomly. To get the url to change once a day check for that day then set the url. Althouhg this will not be random.
So.. if theday==0 call neWurl[0];if theday==1 call neWurl[1];
and so on. I cannot think how to do it randomly and on set days. Without cookies the browser would not know to change the page or not (whether the site has been visited.) Someone smarter may know...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>::: By Batfink :::</title>
<script language="javascript">
function whatday()
{
var today=new Date(),neWurl = new Array(),i;
neWurl[0]="http://www.google.co.uk";
neWurl[1]="http://www.altavista.co.uk";
neWurl[2]="http://www.yahoo.co.uk";
neWurl[3]="http://www.ask.co.uk/";
neWurl[4]="http://www.lycos.co.uk/";

thedate=today.getDate();theday=today.getDay();

if(thedate>0 && thedate<=7)
{document.getElementById("myurl").src=neWurl[0];}
else if(thedate>7 && thedate<=14)
{document.getElementById("myurl").src=neWurl[1];}
else if(thedate>14 && thedate<=21)
{document.getElementById("myurl").src=neWurl[2];}
else if(thedate>21 && thedate<=28)
{document.getElementById("myurl").src=neWurl[3];}
else{document.getElementById("myurl").src=neWurl[4];}
}
</script>
</head>
<body onLoad="whatday()">
<table border="1">
<tr><td>cooeewl</td></tr>
<tr><td width="200"><iframe id="myurl" src=""></iframe></td></tr>
<tr><td>This is a table</td></tr></table>
</body>
</html>