...

View Full Version : infile JS vs external js?



nanocode
05-07-2008, 06:34 PM
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/dynamicindex6/universalcountdown.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:


<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

mrhoo
05-07-2008, 07:19 PM
How, and from where does the javascript get the server time?

shyam
05-07-2008, 07:24 PM
this is what the link you posted(http://www.dynamicdrive.com/dynamicindex6/universalcountdown.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.

shyam
05-07-2008, 07:27 PM
How, and from where does the javascript get the server time?


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() %>'

nottRobin
05-07-2008, 07:33 PM
This is, as far as I can see, the only line that uses php:


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.

nanocode
05-08-2008, 07:55 PM
Thanks Guys,

I modified the countdown script to where I pass in the "servertimestring"

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum