Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to have a javascript re run on a timer

Status
Not open for further replies.

avayaman

Technical User
Joined
Nov 6, 2002
Messages
841
Location
CA
This is a little hard to describe in the header. What I have is a banner program on my website. The banner changes everytime the page is refreshed which was fine before the header was in a frame, as it changed everytime someone went tot anew section of the site. Now because that frame is static while the content changes, the banner does not change. I would like it to refresh itself every 30 seconds or so. It's a cgi script. Here is the script on the page:

<script language="JavaScript" src=" type="text/JavaScript"> </script>

I need some way to have it re-executed every 20 seconds or os. I coudl use an automatic page refresh, but I'd rather not.

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
Do it like this?
[tt]
<head>
<script type="text/JavaScript" id="srcholder" src=""></script>
<script type="text/javascript">
function doit() {
var oscript;
oscript=document.getElementById("srcholder");
document.getElementsByTagName("head")[0].removeChild(oscript);
oscript=document.createElement("script")
with (oscript) {
setAttribute("id","srcholder");
setAttribute("src"," }
document.getElementsByTagName("head")[0].appendChild(oscript);
}
window.onload=doit;
</script>
</head>
[/tt]
 
Amendment:
The onload handler, I really meant this.
[tt]
window.onload=function() {
setTimeout("doit()",30000);
}
[/tt]
 
Thanks, it still does not work though. I changed the cgi links to the directory "bananas" & glarp.cgi rather than ads.cgi. seems to fool some ad filters.

If you can help me figure it out, I'd appreciate it. The full path to the cgi is
I have your code in this web page
Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
sorry, its still ads.cgi not glarp.cgi

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
I just went to the page and see this in the source.
> [tt]etTimeout("doit()",3000);[/tt]
with missing "s". Also I made a mistake on the amendment, it should be set Interval. Hence the correct line to my idea is this.
[tt] [blue]setInterval[/blue]("doit()",3000[blue]0[/blue]);[/tt]
Sorry for the confusion! (If you meant 3 sec, you can of course keep the 3000 instead of 30000.


 
Still does not work. I can't see the inital banner, although I think the timer is working. I have it up on our website at in the top frame. I'm using a meta refresh in that frame every 30 secs to accomplish it right now. I have the new code in a page at If I can't figure it out I will redo the page so the frame only contains the banner & leave it at a meta refresh to change it.

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
I don't know what is the deal here? What happens to the leading s of setInterval? It is again missing. I can read only
[tt][highlight]et[/highlight]Interval("doit()",20000);[/tt]
from the source. What is happening? Is that some kind of mechanism on the server blocking the script?
 
That's strange I can see it no problem when I view source either in FF or IE. I will move it over to the right a bit & re-upload

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
Ok done, do you see all of setinterval now?

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
Now, yes, it is there.

But, it seems you have two head sections and hence
[tt]...getElementsByTagName("head")[0][/tt]
is the wrong section.
 
And why you put head within the body?
 
oops, fixed.

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
I am not sure why you have script tag with src a cgi file rather than .js file??? Should you not in the js file send the cgi thing to the body/iframe?
 
That is the way the banner software is written, I'm not a programmer. I know what a js file is, but I have no idea how to configure one.

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
avayaman, it could well be only that I am not at all what is does on the server-side with cgi. Let me illustrate with a classic js.
[tt]
<html>
<head>
<script type="text/javascript" id="srcholder" src="test.js"></script>
<script language="javascript">
function doit() {
var oscript=document.getElementById("srcholder");
document.getElementsByTagName("head")[0].removeChild(oscript);
var oscript=document.createElement("script")
oscript.setAttribute("id","srcholder");
oscript.setAttribute("src","test.js");
document.getElementsByTagName("head")[0].appendChild(oscript);
}

window.onload=function() {
setInterval("doit()",2000);
}
</script>
</head>
<body>
<iframe name="iframename" id="iframeid" style="position:absolute;width:20%;height:96%;top:1em;"></iframe>
<div id="divid" style="position:absolute;left:25%;top:1em;">any other things</div>
</body>
</html>
[/tt]
with the test.js like this.
[tt]
var x=window.frames["iframename"].document.body.innerHTML;
if (x.match(/\<br/gi)&&(x.match(/\<br/gi).length<10)) {
window.frames["iframename"].document.body.innerHTML=(new Date())+"<br />"+x;
} else {
window.frames["iframename"].document.body.innerHTML=(new Date())+"<br />";
}

//any other functions...
[/tt]
It will show up inside the iframe refreshing every 2 seconds.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top