1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Auto footer copyright year with Javascript

Discussion in 'JavaScript' started by Web_Dev_Chris, Jul 5, 2019.

  1. #1
    I have seen this done with PHP before and have done it myself with PHP. But I realized why not use JavaScript. It's very simple.

    (function (){
    var date=new Date();
    if(document.querySelector("#auto-year-update")!==null){
    document.querySelector("#auto-year-update").innerText=date.getFullYear();
    }
    })();
    Code (JavaScript):
    With this code we would just need to replace the year 2019 with a <span id="auto-year-update"></span> which will then be populated with the current year.
     
    Web_Dev_Chris, Jul 5, 2019 IP
  2. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #2
    The only disadvantage with doing it via JavaScript is your copyright holds little merit since the year is based on the clients computers date. However, nothing will probably ever come out of it.
     
    NetStar, Jul 6, 2019 IP
  3. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    818
    Best Answers:
    7
    Trophy Points:
    320
    #3
    Not sure why you want to do it this way. As @NetStar has noted it is probably a non-issue legally.

    No matter how you are building your pages, adding a copyright via the backend is super simple, so why not do it when you are building your pages? I build all of my pages using FoxPro and use the following snippet to generate the copyright notice:

    
    ********************
    *
    *  Insert copyright on page centering if needed
    *
    ********************
    
    PARAMETERS qCenter
    
    DO CASE
    CASE gTest      &&  Drops through if we are in test mode without adding copyright
    OTHERWISE
    
      \<BR>
      \
     
      IF qCenter
        \<CENTER>
        \
      ENDIF
     
      \<FONT SIZE='1' COLOR='blue'>All content copyright 1984-<<YEAR(DATE())>> by mmerlinn.</FONT>
      \
     
      IF qCenter
        \</CENTER>
        \
      ENDIF
     
      \<BR>
      \
    
    ENDCASE
    
    RETURN
    
    Code (markup):
    Granted that code is not compatible with HTML5, but that would be easy to fix.
     
    mmerlinn, Jul 7, 2019 IP