Jump to content
Sign in to follow this  
penguine

Dynamically add setInterval function

Recommended Posts

Hi How can setInterval function be added to head element. i want setInterval('checkstat()', 2000) to be created dynamically.i tried

					 var  head=document.getElementById('head');				 				var newscript = document.createElement('script');				newscript .type = 'text/javascript';							newscript .setInterval=function(){'checkstat()', 2000};				head.appendChild(newscript );

but it seems to be not working.

Share this post


Link to post
Share on other sites

I think you're trying to do this:

var  head=document.getElementByTagName('head')[0];				var newscript = document.createElement('script');newscript.type = 'text/javascript';			newscript.appendChild(document.createTextNode("setInterval('checkstat()', 2000)");head.appendChild(newscript );

But why create it dynamically? I still how doubts on if this will work, since once the browser finishes loading the head it most likely won't look back there again.

Share this post


Link to post
Share on other sites

So you just want your site to update it's stats by itself right. I'm guessing you got something like a counter.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...