There is a title

<title>[#title#]</title>

This is where the variable is taken from the depths of the CMS. The result of the header, for example:

Эта страница с информацией

Required to add to the title of the date. What would have been like this:

This page with information for January-February 2014

In title js code does not execute. There is document.title.

 <script type="text/javascript"> var d=new Date(); var month=new Array(12); month[0]="Январь"; month[1]="Февраль"; month[2]="Март"; month[3]="Апрель"; month[4]="Май"; month[5]="Июнь"; month[6]="Июль"; month[7]="Август"; month[8]="Сентябрь"; month[9]="Октябрь"; month[10]="Ноябрь"; month[11]="Декабрь"; document.write(month[d.getMonth()]); </script> <script type="text/javascript"> var y = new Date(); document.write(y.getUTCFullYear()); </script> 

This code gets the month + year. And how to make "Month-Next. Month-Year" and add all this to the end title? Maybe there is a solution in php?

    1 answer 1

    On js something like this:

     (function() { var d=new Date(), months="Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь".split(' '), start_month=months[d.getMonth()], start_year=d.getFullYear(); d.setMonth(d.getMonth()+1) //тут хитрость - если больше 11 - то это дата следующего года.... var end_month=months[d.getMonth()],end_year=d.getFullYear(); if (end_year!=start_year) { //чтобы вывести год возле периода декабрь-январь start_month+=' '+start_year; } console.log('Эта страница с информацией за '+start_month+' - '+end_month+' '+end_year); document.title='Эта страница с информацией за '+start_month+' - '+end_month+' '+end_year; })(); 

    http://jsfiddle.net/YDELR/

    http://run.plnkr.co/aEPz9ILUkRE6XcQ1/

    • THANK YOU VERY MUCH! - sleepn0w