Web Connection
Re: How to do Javascript getTime in VFP?
03/15/2010
11:40:24 AM
2W00P0SFJ Show this entire thread in new window
Gratar Image based on email address
From:
Sylvain Bujold
To:
Brett Baggott 
Attachments:
None
Are you sure this is really necessary to be that specific 'getTime()' value from the client ? My guess is that the time value at the end of the URL is to ensure this resource is not cached and therefore you can use the server time as Rick mentioned.

Visitor goes to my URL /example.com/somepage.ww for the first time.

I'm going to serve him a dynamically generated HTML response and in that response I'm going to include my external .js page references in my head section. However, I need to pass a parameter to one of those .js files as shown below that is a Javascript getTime() for when the dynamically generated HTML response was given. That means I have to know the Javascript getTime() as I'm constructing the text I'm going to Response.Write to the client.

Right now, I'm using the code below and it's working fine:

Local loScript loScript = Createobject([MSScriptcontrol.scriptcontrol.1]) loScript.Language = [JavaScript] xGetTime = LTRIM(STR(loScript.eval("var d=new Date();d.getTime();"),20,0))

I don't know how heavy that object is but haven't found a way to do it otherwise for the moment.


I'm not sure I understand what you are trying to do. From the client you can use AJAX callbacks to retrieve server side data from another url.

If you call a client script from the page you can have the server inject HTML into the page using document.write()...

+++ Rick ---

Subject line pretty much says it all. I'm trying to integrate/replace some existing code and I'm having to reverse engineer some server functionality. One thing that's giving me fits is trying to duplicate some HTML that calls a javascript file. All I can see is the HTML output but it calls the file like:

<script type="text/javascript" src="http://www.example.com/js/example.js?1268088105"></script>

I'm sure the server side is inserting the equivalent of the javascript getTime() at the end of the script reference because everything inside the javascript file is about time syncing with the server and such.

Anyone have any ideas? I've considered using wwHTTP to hit a webpage that returns getTime() in plaintext but that seems "wrong" somehow.

EDIT: Forgot wwHTTP can't execute javascript... DOH!

EDIT: Looks like I can use the MSScriptControl. Nice.