PDA

View Full Version : 2 timer scripts are conflicting



kathyc
06-15-2008, 09:22 PM
Hello,

I have 2 scripts running inside my web page that call a timer and they are conflicting with each other.
I don't know how to resolve this issue.

====================================
Script inside web page (page loading script).

<body onLoad="init()">

<div id="loading" style="position:absolute; left:2px; top:198px;">
<img src="loading.gif" border=0></div>

<script>
var ld=(document.all);
var ns4=document.layers;
var ns6=document.getElementById&&!document.all;
var ie4=document.all;
if (ns4)
ld=document.loading;
else if (ns6)
ld=document.getElementById("loading").style;
else if (ie4)
ld=document.all.loading.style;
function init()
{
if(ns4){ld.visibility="hidden";}
else if (ns6||ie4) ld.display="none";
}
</script>

==================================

Script that displays a clock that counts down and refreshes web page every 10 minutes.
This script stopped working once I implemented the script outlined above.

I call this in the head tag of the web page:
<script src="template/countDown.js" type="text/javascript"></script>

This is the contents of the countDown.js file
========================================
var mins
var secs;

function cd() {
mins = 1 * m("10"); // change minutes here
secs = 0 + s(":01"); // change seconds here (always add an additional second to your total)
redo();
}

function m(obj) {
for(var i = 0; i < obj.length; i++) {
if(obj.substring(i, i + 1) == ":")
break;
}
return(obj.substring(0, i));
}

function s(obj) {
for(var i = 0; i < obj.length; i++) {
if(obj.substring(i, i + 1) == ":")
break;
}
return(obj.substring(i + 1, obj.length));
}

function dis(mins,secs) {
var disp;
if(mins <= 9) {
disp = " 0";
} else {
disp = " ";
}
disp += mins + ":";
if(secs <= 9) {
disp += "0" + secs;
} else {
disp += secs;
}
return(disp);
}

function redo() {
secs--;
if(secs == -1) {
secs = 59;
mins--;
}
document.cd.disp.value = dis(mins,secs); // setup additional displays here.
if((mins == 0) && (secs == 0)) {
// change timeout message as required
// window.alert("Press OK to refresh this page.");

// redirects to specified page once timer ends and ok button is pressed
window.location = "mynewsite"
} else {
cd = setTimeout("redo()",1000);
}
}

function init() {
cd();
}
window.onload = init;

=================================

Master_script_maker
06-16-2008, 01:32 AM
try :
var mins
var secs;

function cd() {
mins = 1 * m("10"); // change minutes here
secs = 0 + s(":01"); // change seconds here (always add an additional second to your total)
redo();
}

function m(obj) {
return(obj.substring(0, (obj.indexOf(":")!=-1?obj.indexOf(":"):obj.length-1)));
}

function s(obj) {
return(obj.substring(obj.indexOf(":") + 1, obj.length));
}

function dis(mins,secs) {
var disp=(mins<=9?" 0":" ")+mins+':'+(secs<=9?"0":)+secs;
return(disp);
}

function redo() {
secs--;
if(secs == -1) {
secs = 59;
mins--;
}
document.cd.disp.value = dis(mins,secs); // setup additional displays here.
if((mins == 0) && (secs == 0)) {
// change timeout message as required
// window.alert("Press OK to refresh this page.");

// redirects to specified page once timer ends and ok button is pressed
window.location = "mynewsite"
} else {
cd = setTimeout("redo()",1000);
}
}

window.onload = cd;
there seems to be three different cds, an object, a variable, and a function, you might want to change the names of them