Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2003
    Location
    Bloomsbury, London
    Posts
    98
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Dynamically entering month into the TITLE TAG - possible?

    How can I add the month to the title of a page please?

    Want to do something like

    <TITLE>Special Offers this [MONTH]!</TITLE>

    Tried inserting Javascript I usually use in my HTML to show the show to the title tag, but didn't work of course!

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    
    <!-- Begin
    var months=new Array(13);
    months[1]="January";
    months[2]="February";
    months[3]="March";
    months[4]="April";
    months[5]="May";
    months[6]="June";
    months[7]="July";
    months[8]="August";
    months[9]="September";
    months[10]="October";
    months[11]="November";
    months[12]="December";
    var time=new Date();
    var lmonth=months[time.getMonth() + 1];
    var year=time.getYear();
    document.write(" " + lmonth + " ");
    
    // End -->
    </SCRIPT>
    Many thanks

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,680
    Thanks
    0
    Thanked 230 Times in 225 Posts
    Hi there Azam.biz,

    try it like this...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    
    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    
    <script type="text/javascript">
    //<![CDATA[
    
    var months=new Array();
          months[0]="January";
          months[1]="February";
          months[2]="March";
          months[3]="April";
          months[4]="May";
          months[5]="June";
          months[6]="July";
          months[7]="August";
          months[8]="September";
          months[9]="October";
          months[10]="November";
          months[11]="December";
    
    var now=new Date();
    var num=now.getMonth();
    
    function titleMonth() {
    
          document.title="Special Offers for "+months[num];
    
     }
    onload=titleMonth;
    //]]>
    </script>
    
    </head>
    <body>
    
    <div> </div>
    
    </body>
    </html>
    coothead

  • #3
    New Coder
    Join Date
    Nov 2003
    Location
    Bloomsbury, London
    Posts
    98
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks a million for that. Really appreciate your help coothead.

    Is there any way of inserting month into Title in a search-engine friendly way? I imagine that doing it via Javascript wouldn't be looked upon favourably by the search bots.

    Cheers.


  •  

    Posting Permissions

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