Link to home
Start Free TrialLog in
Avatar of boopsie
boopsie

asked on

Random META Refresh 30-90seconds

Is there any way to create a random interval in the META refresh tag?
I would like the same page on my own server to RANDOMLY refresh every 30 to 90 seconds.

Avatar of a.marsh
a.marsh

As far as I know it cannot be done with just HTML. There are two ways I can think of:

1 - Use server side scripting to generate the META tag - let us know what you have available and then we can put a solution together for you.

2 - Use javascript:

<html>
<head>
<script language="javascript">
<!--

refreshString = "window.location.reload();";
randVal = (Math.round(Math.random()*(10-5)))+5;;

window.setTimeout(refreshString, randVal * 1000);

//-->
</script>
</head>
<body>
hello!
</body>
</html>


:o)

Ant
Whoops - slight mistake change:

randVal = (Math.round(Math.random()*(10-5)))+5;;

to:

randVal = (Math.round(Math.random()*(90-30)))+30;



I just used smaller numbers while testing it. :o)

Ant
ASKER CERTIFIED SOLUTION
Avatar of james_beilby
james_beilby

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I was thinking of that James, but (I might be getting confused with something else) I wasn't convinced it would work....especially in different browsers.

Ant
Well it works in Internet Explorer and Netscape which is good enough for me - document.write() is usually pretty reliable when loading the page. But if you're going to use JavaScript at all, you might as well use the window.setTimeout() approach.
Avatar of boopsie

ASKER

Thank you James, it works perfect!
I've tacked on an extra 100 for a job well done.