1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

How can I get an automatic "last updated" in my web page?

Discussion in 'Web Design & Development' started by Podman, Mar 16, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. Podman

    Podman Thread Starter

    Joined:
    Mar 16, 2008
    Messages:
    3
    I haev been designing a web page for my wife. I am far from a web designer but have been quite chuffed with the results so far. She has just asked if it would be possible for me to add into the bottom of the page a "Last updated" section so people know the site is contstantly being updated.

    The site is css style sheet with normal HTML pages. Could anybody tell me what code I would need to enter into the html of each page to get a "Last updated" section please.

    Any help would be greatly appreciated.

    Thanks
    Pod.
     
  2. Sequal7

    Sequal7

    Joined:
    Apr 14, 2001
    Messages:
    2,382
    You can use javascript, place this where you want the text to display (NOTE: If you are using a webpage editing program like frontpage, dreamweaver or similar you will need to be in source or code view for inserting this to work)
    Code:
    [B]<script type="text/javascript">[/B]
    
    <!--
    var m = "This page was last updated: " + document.lastModified;
    var p = m.length-8;
    document.writeln("<center>");
    document.write(m.substring(p, 0));
    document.writeln("</center>");
     -->
    </script>
    You can chane the text displayed by changing "This page was last updated: " to your own statement and you can change document.writeln("<center>"); to document.writeln("<left>"); or document.writeln("<right>");. Just make sure to change the closing document.writeln("</center>"); to the same /left or /right as the first alignment properties

    Or, you could use built in code (insert > date > automatically update) in frontpage or dreamweaver etc so that when you re-open the page, it updates that field automatically.
     
  3. Podman

    Podman Thread Starter

    Joined:
    Mar 16, 2008
    Messages:
    3
    Brilliant! Thanks very much, I am using Kompozer, I do have dreamweaver and frontpage but Kompozer seemed the easiest to get straight into using.
     
  4. Sequal7

    Sequal7

    Joined:
    Apr 14, 2001
    Messages:
    2,382
    Komposer is very good and very easy to use, unfortunately it does not have an insert/auto date function so you would need to use the code I gave you in the previous post. (this can also be accomplished with PHP, ASP, PERL etc..)

    NOTE: You can click the area you want the date to show on the page in html view, then click the code view and your mouse will be in the correct place, paste that code and it will show once you view the webpage.
     
  5. MMJ

    MMJ Guest

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    the script tag should look like <script type="text/javascript">

    also it is preferable to use the dom to insert content into the page, not document.write.

    in the head:
    PHP:
    <script type="text/javascript">
    onload = function(){
        
    document.getElementById("lastModified").innerHTML "Page last changed " document.lastModified.split(" ")[0];
    }
    </script>
    later on in the body:

    HTML:
    <span id="lastModified"></span>
    good read: http://www.quirksmode.org/js/lastmod.html
     
  6. Podman

    Podman Thread Starter

    Joined:
    Mar 16, 2008
    Messages:
    3
    I am in the uk, how can I get it to show as dd/mm/yyyy rather than mm/dd/yyyy ?
     
  7. MMJ

    MMJ Guest

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    PHP:
    <script type="text/javascript">
    var 
    pcs document.lastModified.split(" ")[0].split("/");
    var 
    date pcs[1] + '/' pcs[0] + '/' pcs[2];
    onload = function(){
        
    document.getElementById("lastModified").innerHTML "Page last changed " date;
    }
    </script>
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/693929