Web Connection
Re: How to do Javascript getTime in VFP?
03/18/2010
10:26:50 AM
2W30ME865 Show this entire thread in new window
Gratar Image based on email address
From:
Brett Baggott
To:
Rick Strahl 
Attachments:
None
I was trying to duplicate an existing mechanism _exactly_.

However, like you and Sylvain have alluded to, this functionality existed strictly to avoid caching so it's just as well to use the Server's time via VFP.

I still don't get it. Why would you want to eval JavaScript on the server??? It's still going to give you a server time...

You'll want to do this via Ajax. Why not just do:

<script type="javascript/text"> document.write( new Date().getTime() ); </script>

where you need the date in the output.

If you need to pass the date to the server use an AJAX callback to pass the client date to VFP which can then read it and do something with it and if necessary return the result back to the client which can then inject it into the document.

+++ Rick ---


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.