Skip to content

Instantly share code, notes, and snippets.

@Akhu
Created May 2, 2018 18:06
Show Gist options
  • Save Akhu/89981829e3d897394fba670c1da1bdcb to your computer and use it in GitHub Desktop.
Save Akhu/89981829e3d897394fba670c1da1bdcb to your computer and use it in GitHub Desktop.
Getting meta tag on a web page
function getMetaTags() {
var metas = document.getElementsByTagName('meta');
var ogMetasKey = "og:";
for(var i = 0; i < metas.length; i++){
if(metas[i] !== undefined){
var currentMeta = metas[i];
if(currentMeta.getAttribute('property') !== null && currentMeta.getAttribute('content') !== null){
if(currentMeta.getAttribute('property').indexOf(ogMetasKey) !== -1) {
console.log(currentMeta.getAttribute('property'), currentMeta.getAttribute('content'));
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment