如何从带有JavaScript的元标记中获取信息? [英] How do I get the information from a meta tag with JavaScript?
本文介绍了如何从带有JavaScript的元标记中获取信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要的信息是元标记。当 property =video
?
The information I need is in a meta tag. How can I access the "content"
data of the meta tag when property="video"
?
HTML:
<meta property="video" content="http://video.com/video33353.mp4" />
推荐答案
您可以使用:
function getMeta(metaName) {
const metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute('name') === metaName) {
return metas[i].getAttribute('content');
}
}
return '';
}
console.log(getMeta('video'));
这篇关于如何从带有JavaScript的元标记中获取信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文