1

I need to get the date from this meta on my page using javascript:

There are two dates for effective and Expires, the date I need to get is the Expires.

Is there a way to get it? I tried string methods, split but it doesn't work :/

  • http://stackoverflow.com/questions/1036351/is-it-possible-to-use-jquery-to-read-meta-tags –  Apr 05 '13 at 23:00
  • http://www.webmasterworld.com/javascript/3224334.htm –  Apr 05 '13 at 23:00

2 Answers2

0

You can get data from meta tags using querySelector, for example author would be:

var authorTag = document.querySelector('[name=author]');

Here's a function which should do want you want for the Expires date:

function getExpires() {
    var expiresTag = document.querySelector('[HTTP-EQUIV=expires]');

    try {
        return expiresTag.content;
    } catch(e) {
        console.log('Unable to get expires meta content');
        return '';
    }
}
tagawa
  • 4,184
  • 1
  • 24
  • 34
-1
var metas = document.getElementsByTagName["meta"];

and loop through finding the tag you want:

for (var i=0; i<metas.length;i++) {  
  if (metas[i].getAttribute("itemprop")) {

    var theTagValueINeed = metas[i].getAttribute("itemprop");

  }
}
KingKongFrog
  • 12,668
  • 17
  • 63
  • 111