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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    infile JS vs external js?

    Hey Guys,

    I'm a pretty big newbie to javascript and came across a countdown script that runs off the server clock.
    http://www.dynamicdrive.com/dynamici...lcountdown.htm

    It works great but only when the code is directly placed in the asp file. Once I put the exact same code in a .js file and include it using the normal include tags:

    Code:
    <script type="text/javascript" src="js/countdown.js"></script>
    It stops working. Does anyone know why is this happening? Possibly because it needs to be in the asp file to get the time? Is there anyway I could make this work to keep my asp/html clean?

    Much Thanks

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    726
    Thanks
    35
    Thanked 132 Times in 123 Posts
    How, and from where does the javascript get the server time?

  • #3
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    this is what the link you posted(http://www.dynamicdrive.com/dynamici...lcountdown.htm) says on the topic
    Requirement: The page running this script must either be PHP, SSI (server side includes), or ASP enabled, as the script needs to rely on one of these technologies to access your server's time.
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by mrhoo View Post
    How, and from where does the javascript get the server time?
    Code:
    var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #5
    New Coder
    Join Date
    May 2008
    Posts
    12
    Thanks
    0
    Thanked 2 Times in 2 Posts
    This is, as far as I can see, the only line that uses php:

    Code:
    var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="&#37;B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
    So you could place this outside the script and then include the rest from a JS file if you wanted.... however, the you'd still need to be including this line in every page anyway, kinda defeating the point of putting it in an external file I imagine.

    I don't understand why it needs to get the time from PHP anyway. I mean then it is using hte server time rather than the client's system time which might be wrong... but you can get the timezone offset using the "getTimezoneOffset" property, so as long as you don't care about the client's timezone being wrong you can use that.

  • #6
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Guys,

    I modified the countdown script to where I pass in the "servertimestring"
    Code:
    var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
    Rather than build it in the JS. That way I could place the main part of the script in an external file and just have the call script within my HTML file. You can see an example of the embedded vs external JS at:
    http://www.fuse11.com/examples/countdown/test1.php
    http://www.fuse11.com/examples/countdown/test2.php

    @nottRobin - The time is meant to be based off the server time since it's goal is to countdown to a launch time which is the same everywhere around the world. Rather than countdown to a time based of the user clock.

    Thanks.


  •  

    Posting Permissions

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