Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Script works under FF and IE, but not chrome (??)

    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

    Code:
    <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:

    Code:
    <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>

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    it didn't work in firefox until I changed
    type="hidden"
    to

    type="button"

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by TinyScript View Post
    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

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also check our my new website

    http://www.mymaplemesos.com/

    Pretty nice!

  • #5
    Regular Coder
    Join Date
    Mar 2008
    Posts
    301
    Thanks
    2
    Thanked 30 Times in 30 Posts
    Quote Originally Posted by veecrawn View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •