开发者

Some browsers not recognizing meta tags added via Javascript

开发者 https://www.devze.com 2023-01-21 14:53 出处:网络
I\'m making some examples for javascript; they are not really usable. This one is interesting - it works on Chrome (and other using webkit), and Safari. So can someone suggest any reason why it is not

I'm making some examples for javascript; they are not really usable. This one is interesting - it works on Chrome (and other using webkit), and Safari. So can someone suggest any reason why it is not working in the other browsers I've tested?

One possible explanation is that the other browsers does not read the meta tags after the page is loaded, or does not read new added ones.

   if (document.createElement) {
   var meta = document.createElement('meta');
   var metaContent = '2; URL=http://localhost/new.html'; 
   meta.setAttribute('http-equiv', 'refresh');
   meta.setAttr开发者_运维百科ibute( 'content', metaContent );
   document.getElementsByTagName('head')[0].appendChild(meta);
   }


Most browsers read the meta tags before processing any Javascript. You can inject new meta tags the way that you are coding it but the browsers themselves will not do anything with the new tags. Though the new metas will be available to other code running on the page that is called after the injection.


Meta tags have to be in the first 512 characters, when the page loads. If they are not, they will stay in the DOM but not be recognized by the browser.

0

精彩评论

暂无评论...
验证码 换一张
取 消