Link to home
Start Free TrialLog in
Avatar of davideo7
davideo7Flag for United States of America

asked on

Using Javascript, make my page load another page in a delayed time limit

I have a script which you can see in the code below.

What I want it to do though is instead of refreshing the current page in 300 seconds, I want it to load the current page in 300 seconds as if it was loading another page.  Refresh just re-submits post variables but simply just loading the same page again could avoid this.

So, how can I make this script load it's own page again within 300 seconds without using the refresh/reload method?
<script language='javascript'>
		function refreshEvery5Min()
		{
			setTimeout('location.reload(true);',300000);
		}
		onload=refreshEvery5Min();
	</script>

Open in new window

Avatar of lharrispv
lharrispv
Flag of United States of America image

The simplest way would be if JS had a isPostback method like in asp.  Unfortuently they don't.  All is not lost though.

Check this thread out.  The accepted solution will tell you how to do a isPostback in JS.
https://www.experts-exchange.com/questions/23182011/if-a-page-is-PostBack-in-Javascript.html
ok so knowing that.  set your code up to create your variables etc within a if statement.  If it is not postback then do blah.  If it is then don't do blah.  That way when the page posts back you won't have to worrry about redoing the stuff you don't want it to do.
Avatar of davideo7

ASKER

What if I simply just want it to go to a different url after a certain amount of seconds?
<html>
<head>
<script type="text/javascript">
<!--
function delayer(){
    window.location = "../javascriptredirect.php"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 5000)">
<h2>Prepare to be redirected!</h2>
<p>This page is a time delay redirect, please update your bookmarks to our new
location!</p>

</body>
</html>

http://www.tizag.com/javascriptT/javascriptredirect.php
ASKER CERTIFIED SOLUTION
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

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
ok that is teh second time today someone posted almost exactly the same thign I did and I didn't get any points.. what is up with that?
Yours was just a copy and paste job from an external site and wasn't very specific and didn't work.  With his he put more time into it and customized the code to exactly what I needed.  I'm sorry.
Actually I did take time... had to google it.. read it over and make sure it was what you needed.  Also gave you a link to it so you could learn oh and cause I do not plagerise... but  as the old adiage says... teach a man to fish feed him for life give a man a fish feed for a day.....

hope you enjoy your one meal.....