javascriptbookmarkletinformation-retrievalhcarddata-scrubbing

Get an article's title/author/date info with Javascript


I'm trying to build a bookmarklet that will get the current page/article's author and date information, for referencing purposes. I know that I can get the Page title and url with document.title and document.URL but I'm drawing a blank when it comes to the other information. Any ideas?


Solution

  • If the site puts such information in a META tag you can do this:

    var author = "";
    var info = document.getElementsByTagName('META');
    for (var i=0;i<info.length;i++) {
      if (info[i].getAttribute('NAME').toLowerCase()=='author') {
        author = info[i].getAttribute('CONTENT');
      }
    }
    

    For the site you mention in your comment, you need to do this non-standard processing

      var author = "";
      var other = document.getElementsByTagName('li');
      for (var i=0;i<other.length;i++) {
        if (other[i].className.toLowerCase()=='author') author=other[i].getElementsByTagName('a')[0].innerHTML;
      }
      alert(author)
    }