Skip to content

Instantly share code, notes, and snippets.

@ogaaryo
Last active November 10, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogaaryo/9119f7ca9309391b24d40a0329c6fcbd to your computer and use it in GitHub Desktop.
Save ogaaryo/9119f7ca9309391b24d40a0329c6fcbd to your computer and use it in GitHub Desktop.
get html meta information js
var url = location.href;
var title = document.title;
var description = document.getElementsByName ('description').item(0).content;
var canonical_url = getCanonicalUrl();
console.log(url + '☆' + title + '☆' + description + '☆' + canonical_url)
function getCanonicalUrl() {
var links = document.getElementsByTagName("link");
for (var i = 0; i < links.length; i++) {
if (links[i].rel) {
if (links[i].rel.toLowerCase() == "canonical") {
return links[i].href;
}
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment