Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Get the Last modified date of an external text file?

  1. #1
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Get the Last modified date of an external text file?

    Hi there all,

    I'm new to JavaScript, so excuse me if this is in the "gosh that's so simple" area.

    I was wondering if there was a simple JS function to get the last modified date of an external text file. I've tried the "document.lastmodified" function, but (obviously) this returns the current web pages' date.

    Its just for a simple price list/data table page that will look for the newly uploaded "prices.txt" and use that as a "Prices correct as at: 08/05/06" type of thing.

    all the best,

    Tony L.
    Last edited by KegExpress; 05-08-2006 at 11:56 PM. Reason: I wanted email notification turned on.

  2. #2
    Join Date
    Apr 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    document.lastmodified will work only with the current document. For external text file my suggestion is to use server side script instead.

    Here is an example on how to do it using ASP.Net:
    Code:
    Dim strLastModified As String
    strLastModified = System.IO.File.GetLastWriteTime(Server.MapPath("prices.txt")).ToString("D")
    lblMsg.Text = "Prices correct as at: " & LastModified

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Otaku is right.

    That's a server side thing... you can't do stuff on the server client side. Kinda the point, sadly.

    However, i'd look into PHP before ASP. Your choice though.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah Dang,

    I wanted the "Quick-And-Dirty" answer, seems a bit OTT to have to learn yet another programing language

    thanks of the help anyway,

    Tony L.

    PS: a QAD answer, after looking for a few days for it - now that's optomism!! lol

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The only chance is if the file stores that data in a place you can access it. Might work... dunno.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I wanted the "Quick-And-Dirty" answer, seems a bit OTT to have to learn yet another programing language
    For just that one task, maybe, but a server-side language will serve you admirably in the future.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Apr 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    However, i'd look into PHP before ASP. Your choice though.
    I strongly recommend ASP.Net.
    By the way djr33, ASP.Net and ASP are not the same thing. It's like comparing java and javascript.

  8. #8
    Join Date
    Apr 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    In fact we can do it using javascript.

    Demo:
    http://www.getelementbyid.com/demo/LastModified/

    Simply place <span id="LastModified"></span> where you want the message to be displayed and change the path for: src="prices.txt"

    Code:
    <html>
    <head>
    <title>Last Modified</title>
    <script type="text/javascript">
    function getLastMod(){
    	var myFrm = document.getElementById('myIframe');
    	var lastModif = new Date(myFrm.contentWindow.document.lastModified);
    	document.getElementById('LastModified').innerHTML = "Prices correct as at: " + lastModif.toLocaleString();
    }
    </script>
    </head>
    <body>
    <span id="LastModified"></span>
    
    <iframe id="myIframe" onload="getLastMod()" src="prices.txt" style="display:none;">
    </iframe>
    
    </body>
    </html>

  9. #9
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by otaku
    In fact we can do it using javascript.
    Certainly. Two ways, at least. However, if this information needs to be displayed, your original suggestion of a server-side approach is far superior. Even if there's no necessity, using the server would still be preferable.

    That fails in Opera, at the very least.

    var lastModif = new Date(myFrm.contentWindow.document.lastModified);
    The contentWindow property is a non-standard feature, and not all browsers implement it. Though it could be feature tested alongside the contentDocument property, one should also ensure that the document object is accessible at all:

    Code:
    var doc;
    
    if ((doc = myFrm.contentDocument)
        || (myFrm.contentWindow && (doc = myFrm.contentWindow.document))) {
      /* ... */
    }
    Mike

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I strongly recommend ASP.Net.
    Closed-source, ugly, platform- and webserver-dependant, and, in its most common usage, a variant of a language that was most certainly never designed for web programming (yes, I know ASP.NET can use other, more suitable languages, but the point is that most people don't, yourself included from what I've seen of your examples so far)? Oh, Mono is trying hard enough, but they haven't got anything even resembling a usable ASP.NET parser yet -- it can only parse C#, for a start. If you want a pre-compiled web backend language, use JSP, rather than Microsoft's poor attempt at a clone.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •