• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

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?
1 Solution
i don't think javascript can do that. using a server-side script is a better choice. take a look a this link,

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.

StendecAuthor Commented:
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.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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.
StendecAuthor Commented:
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.

"get jiggy with some CGI" <- Dude that's hilarious!

The only way you may be able to do it is with ActiveX

But if the host doesn't support any other server side scripting, I don't know if you can do this either.  Only client-side approach I can see though.  Once you make your ActiveX object, it's just like using the file system object in ASP.

Otherwise....if they could upload a basic html page that just contained the image, then you could use the lastmodified approach in a page with a whole bunch of iframs pointing to those documents.  Sorry... that's all i got.  Go on and get jiggy with your bad self :)
StendecAuthor Commented:

tested the following:

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

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...
StendecAuthor Commented:
And by the way, tahnks to all of you for the input! Wakie, Plop, Third, Memerot...

Appreciate the effort!

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now