Last active
November 10, 2017 14:43
-
-
Save ogaaryo/9119f7ca9309391b24d40a0329c6fcbd to your computer and use it in GitHub Desktop.
get html meta information js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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