Link to home
Start Free TrialLog in
Avatar of Stendec
Stendec

asked on

using JavaScript to retrieve an image's date or time value

I'm running a webcam and I was wondering if there was a more dynamic way in which I could fetch the time or date of an image file remotely using JavaScript...  eg: it's "last modified" or similiar value.  I don't think it's possible outside some obvious cgi, asp, etc. deal but wondering if someone knows something I don't and if there is some obscure JavaScript method for getting a file's info?
Avatar of third
third
Flag of Philippines image

i don't think javascript can do that. using a server-side script is a better choice. take a look a this link,

http://www.developerfusion.com/show/1971/
Just a suggestion, but perhaps you could create a function that would execute every "n" seconds and would increment some sort of a count that you could tack onto the end of your image, like:

<img src="pic" + count + ".jpg">

Bear in mind, this is only a guide & I don't have much time to write your function, but best of luck with trying.

Regards,
Wakie.
Avatar of Stendec
Stendec

ASKER

Thanks Wakie...

That's how I'd set up things normally for a cam doodad, which I'm sure is what you were getting at, having the images loaded up with a timestamp as part of the image files title.  Problem is the client I'm doing a site for has a CCTV deal and program that doesn't/can't stamp the image title (dumb!).  Add to that their hosting service setup doesn't allow for any CGI, etc (again, super dumb!).  Hence why I was looking for a possible workaround using JavaScript via the browser.  I think if they're serious about properly instituting this webcam they'll have to break down and "enhance" their hosting service so I can get jiggy with some CGI etc and do this properly.  I'll leave the question open a touch longer just to see what other suggestions if any are out there.  Though I'm thinking "third" was right, can't be done w/ clientside JavaScript.
It is possible to get a file's modified date using JavaScript, but information is only returned accurately when the file is on the local computer.

The last modified date can be found in the document.lastModified variable.
Avatar of Stendec

ASKER

Forgot about that one... Thanks Plop.

That only works for the document's "time stamp" as far as I can tell, not for any of the images in it?
Hi Stendec,

Perhaps you could set your webcam to overwrite the existing image file? I haven't had any experience with webcams whatsoever. But, you may be able to create a simple meta refresh if it was possible.

Cheers,
Wakie.
ASKER CERTIFIED SOLUTION
Avatar of memerot
memerot

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stendec

ASKER

Nice...

tested the following:

    theX = new ActiveXObject("Scripting.FileSystemObject");
    theFile = theX.GetFile("test_foobar.gif");
    alert(theFile.DateLastModified);

Seems to work!  Though it does pop up a warning dialog regarding the ActiveX in IE.  I think there might be a workaround to that though(?).  Didn't even think to use ActiveX, thanks memrot! quick thinking! I'll consider the matter closed at this point.

I'm still going to get them to modify their hosting service to something more substantial and ultimately do this correctly, but for the timebeing this will do fine...
Avatar of Stendec

ASKER

And by the way, tahnks to all of you for the input! Wakie, Plop, Third, Memerot...

Appreciate the effort!