Skip to content

Instantly share code, notes, and snippets.

@joeworkman
Created March 22, 2019 21:26
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 joeworkman/96d161e8b5761b72d6a461e96f8995c4 to your computer and use it in GitHub Desktop.
Save joeworkman/96d161e8b5761b72d6a461e96f8995c4 to your computer and use it in GitHub Desktop.
This will get the property name of meta tag and it will take that value and set the input value.
function getMeta(metaName) {
const metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute('property') === metaName) {
return metas[i].getAttribute('content');
}
}
return '';
}
document.querySelectorAll('input[name=text]')[0].value = getMeta("og:title");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment