admin管理员组文章数量:1315033
I want to check a meta tag exist on webpage.
I have tried this :
document.getElementsByTagName("meta[http-equiv:Content-Type]").length
But this alway return 0. How can I do that? I want to do it by using javascript. Not jQuery.
I want to check a meta tag exist on webpage.
I have tried this :
document.getElementsByTagName("meta[http-equiv:Content-Type]").length
But this alway return 0. How can I do that? I want to do it by using javascript. Not jQuery.
Share Improve this question asked Jan 27, 2014 at 18:56 CoolCool 3482 gold badges11 silver badges32 bronze badges 01 Answer
Reset to default 9var x = document.querySelector('meta[http-equiv="Content-Type"]');
console.log(x);
x
has a reference to the meta tag if found. It will be null
otherwise, so you can use if (x) {
Live demo (click).
Here's a way to do it if querySelectorAll
isn't supported (older browsers)
var metas = document.getElementsByTagName('meta');
var found;
for (var i=0; i<metas.length; ++i) {
var meta = metas[i];
if (meta.getAttribute('http-equiv') === "Content-Type") {
found = meta;
break;
}
}
console.log(found);
Live demo (click).
found
has a reference to the meta tag if it existed. You could do if (found) {
to determine whether or not it exists.
本文标签: htmlCheck meta tag exist on webpage using javascriptStack Overflow
版权声明:本文标题:html - Check meta tag exist on web-page using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741971569a2407871.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论