Jump to content

setInterval


bw83

Recommended Posts

<html>  <body>	<script>	  setInterval("window.location='http://api.msappspace.com/proxy/relay.proxy?opensocial_authtype=SIGNED&opensocial_token=DzRwBJccOvQZ/Sonv4hJh7skDhuH6y1HLefcY6A0NQkF2J/ncbjhIKkdlZVRQyHkTHrMFlLRMTZXR29cZdrJA9ZxL3OVle96/P2Oz/Yyu6s=&opensocial_url=http%3A//dynamic-lb2.mobwarsapp.com/mob/heal%3Fuser_id%3D128559318%26level%3D87%26session_id%3D9abc68f653ee41a4ba1f8ce7146f0f0fda1dee09%26session_key%3D5d08902658805a3df0cace400de10624d375f299%26nocache%3D1220473339965';", 400);	</script>  </body></html>

Im trying to run this script repeating it indefinately refreshing this page at a 400ms interval but as soon as i get a false return it stops. Am i missing something that makes it continue past that point?

Link to comment
Share on other sites

What do you mean you get a false return? This page will just redirect to the URL there after 400ms, is that all you're trying to do? Once it redirects once it's not going to run the code again, because it redirected and it's on the other page now.

Link to comment
Share on other sites

That must be why I think it stops. The link is to another JS that im trying to re-execute indefinately. I guess thats what the problem is if its redirecting to the other page and stopping I must be using the wrong syntax in the begining. Basically I just want it to keep refreshing that url at a 400ms interval.

Link to comment
Share on other sites

Use an iframe on the page to hold the page that you want to refresh. Your Javascript code can set the URL of the iframe instead of the URL of the entire page. It would also be good to add another number onto the URL that changes so that it gets a new copy each time instead of loading the cached version. You can use the date object to get that number.

function refresh_frame(frame_id, theurl){  var fr = document.getElementById(frame_id);  var now = new Date();  now = now.valueOf();  fr.src = theurl + "&now=" + now;}

You can run that function with setInterval, just send the function the frame ID and the URL you want to load in it.

Link to comment
Share on other sites

<html> <body><IFRAME name="Heal" src="http://api.msappspace.com/proxy/relay.proxy?opensocial_authtype=SIGNED&opensocial_token=o7H9ZTCi1TvHlRTZXxMzWF6DGlOE9a2bFqpVxwrqB9XdNbs3QaY/eps3Nm+3VTXopYM87CjwJ/D3C8SvRWvWMxAylK2n2CyJHLvbucKsyqU=&opensocial_url=http%3A//mob-dynamic-lb1.mobsters02.com/mob/heal%3Fuser_id%3D128559318%26level%3D88%26session_id%3D9abc68f653ee41a4ba1f8ce7146f0f0fda1dee09%26session_key%3D6b22e11a566c543a8606ea160af714da868bcc56" width=800 height=200 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto></IFRAME>  <script>   setInterval(function refresh_frame(Heal, theurl), 400);{  var fr = document.getElementById(Heal);  var now = new Date();  now = now.valueOf();  fr.src = theurl + "&now=" + now;});   </script>  </body></html>

I removed the cache from the link and verified that the link is still working. This is the code that i tried to ues the refresh_frame with but i must be nesting it in the setInterval wrong. I have also tried to use the same link in the iFrame in the rest where it says "theurl" to make sure thats not my mistake and I get an initial success of the page working but not getting a refresh in any of the instances.

Link to comment
Share on other sites

You don't put the function definition into the call to setInterval, you just define the function and then use it with setInterval. This is how it should be set up:

<html>  <head>	<script type="text/javascript">	var frame_url = "http://api.msappspace.com/proxy/relay.proxy?opensocial_authtype=SIGNED&opensocial_token=o7H9ZTCi1TvHlRTZXxMzWF6DGlOE9a2bFqpVxwrqB9XdNbs3QaY/eps3Nm+3VTXopYM87CjwJ/D3C8SvRWvWMxAylK2n2CyJHLvbucKsyqU=&opensocial_url=http%3A//mob-dynamic-lb1.mobsters02.com/mob/heal%3Fuser_id%3D128559318%26level%3D88%26session_id%3D9abc68f653ee41a4ba1f8ce7146f0f0fda1dee09%26session_key%3D6b22e11a566c543a8606ea160af714da868bcc56";	function refresh_frame(frame_id, theurl)	{	  var fr = document.getElementById(frame_id);	  var now = new Date();	  now = now.valueOf();	  fr.src = theurl + "&now=" + now;	}		setInterval('refresh_frame("Heal", frame_url);', 400);   </script>  </head>  <body>	<IFRAME id="Heal" width=800 height=200 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto></IFRAME>	<script type="text/javascript">	document.getElementById("Heal").src = frame_url;	</script>  </body></html>

Link to comment
Share on other sites

Thank you very much it works perfect. Ive added in a prompt window also so I can change variables and set variables in the links that I can edit. Once again thank you very much it works perfect and now that I see what I want and not examples that dont apply to me it makes so much more sense.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...