Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some browsers not recognizing meta tags added via Javascript

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.setAttribute( 'content', metaContent );
   document.getElementsByTagName('head')[0].appendChild(meta);
   }
like image 731
Bakudan Avatar asked Oct 19 '25 06:10

Bakudan


1 Answers

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.

like image 102
conceptDawg Avatar answered Oct 21 '25 20:10

conceptDawg