PDA

View Full Version : How do I get different information to appear on refresh ?


Deykamol
06-12-2008, 03:09 PM
I once had this "Random facts" iframe on my web page, and every time the viewer refreshed the iframe a different piece of nonsense was shown.
Annoyingly, I can't remember anything about the coding.
Can someone poke me in the right direction ? Refer me somewhere helpful, or indeed give me the answer here ?
Much appreciated (:

jcdevelopment
06-12-2008, 03:17 PM
I just posted a similiar answer in this forum, if you want just change the names and use only one iframe

http://www.codingforums.com/showthread.php?t=141872

Deykamol
06-12-2008, 03:43 PM
Thanks.
But that has left me slightly confused ? I think the randomising URLs made my head spin, so I wasn't quite sure of his question, hence I didn't understand your answer.

jcdevelopment
06-12-2008, 03:49 PM
ok, well to get a random fact, or rather random HTML page, which it would have to be i am assumin you would have to set arrays, unless you wanted to use serverside language. Then you would have to use PHP on that, but here is what switching the urls in an iframe would look like.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var srcArr = new Array();
srcArr[0]="pg1.html";
srcArr[1]="pg2.html";
srcArr[2]="pg3.html";

window.onload = function (){
var ranNum=Math.floor(Math.random()*(srcArr.length));
document.getElementById("randomFrme").src=srcArr[ranNum];
}
</script>
</head>

<body>
<iframe id="randomFrme"></iframe>
</body>
</html>


Is that what you were looking for?

Deykamol
06-12-2008, 03:55 PM
Aha, I think so !
Thankyou very much for your help (: