...

View Full Version : Script works under FF and IE, but not chrome (??)



veecrawn
03-19-2009, 09:31 PM
Hello and hi everyone!

The following script works perfectly under FF and even IE, but doesn't do anything under Chrome

It's a simple chronometer (I'm a beginner) to calculate gold gained, at the rate of 7 per second.

In the HEAD section


<script language="JavaScript">
<!--
var startTime = 0;
var start = 0;
var end = 0;
var diff = 0;
var timerID = 0;
function chrono(){
end = new Date();
diff = end - start;
diff = new Date(diff);
var msec = diff.getMilliseconds();
var sec = diff.getSeconds();
var min = diff.getMinutes();
var hr = diff.getHours()-19;
hr=0;
var gold = hr*60*60*7+min*420+sec*7;
document.getElementById("chronotime").innerHTML = gold;
timerID = setTimeout("chrono()", 10);
}
function chronoStart(){

start = new Date();
chrono();
}
function chronoContinue(){
document.chronoForm.startstop.value = "stop!";
document.chronoForm.startstop.onclick = chronoStop;
document.chronoForm.reset.onclick = chronoReset;
start = new Date()-diff;
start = new Date(start);
chrono();
}
function chronoReset(){
document.getElementById("chronotime").innerHTML = "0:00:00:000";
start = new Date();
}
function chronoStopReset(){
document.getElementById("chronotime").innerHTML = "0:00:00:000";
document.chronoForm.startstop.onclick = chronoStart;
}
function chronoStop(){
document.chronoForm.startstop.value = "start!";
document.chronoForm.startstop.onclick = chronoContinue;
document.chronoForm.reset.onclick = chronoStopReset;
clearTimeout(timerID);
}
//-->
</script>

In the body. I have the script called with a onLoad for a picture above this:


<div id ="chronojack" >
<span id="chronotime">0</span>
<form name="chronoForm">
<input type="hidden" name="startstop" value="start!" onClick="chronoStart()" />
<input type="hidden" name="reset" value="reset!" onClick="chronoReset()" />
</form>

</div>

TinyScript
03-20-2009, 07:36 AM
it didn't work in firefox until I changed
type="hidden"
to

type="button"

veecrawn
03-22-2009, 10:12 PM
it didn't work in firefox until I changed
type="hidden"
to

type="button"

Thanks.

To anyone wondering, Chrome won't call the script if it's loaded within an image. You absolutely have to load it within the body tag. Sad:(

veecrawn
07-20-2009, 09:24 PM
Also check our my new website :D

http://www.mymaplemesos.com/

Pretty nice!

fside
07-21-2009, 01:56 PM
Thanks.

To anyone wondering, Chrome won't call the script if it's loaded within an image. You absolutely have to load it within the body tag. Sad:(

It's generally considered good practice to load your main script just at the closing body tag. There are exceptions where you'd want script in the HEAD, or in bits and pieces up the page. But it allows the page to display simply for dialup, even if not the view you might want people to see if script changes much around.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum