Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Add meta tag

Reply
Thread Tools

Add meta tag

 
 
J1C
Guest
Posts: n/a
 
      05-16-2005
How can I programatically add meta tags with javascript?

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-16-2005


J1C wrote:

> How can I programatically add meta tags with javascript?


The same way you create and add other elements, with the W3C DOM:
var meta;
if (document.createElement &&
(meta = document.createElement('meta'))) {
// set properties
meta.name = "God";
meta.content = "Kibo";

// now add the meta element to the head
document.getElementsByTagName('head').item(0).appe ndChild(meta);
}

See also
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-37041454>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Grant Wagner
Guest
Posts: n/a
 
      05-17-2005
"J1C" <> wrote in message
news: oups.com...
> How can I programatically add meta tags with javascript?


In browsers that support it:

var meta = document.createElement('meta');
meta.name = 'author';
meta.content = 'Your Name';
document.getElementsByTagName('head')[0].appendChild(meta);

However, since the META tag data is mostly for the benefit of search
engines, what does appending a META tag after the page is loaded buy
you? For example, the following doesn't work in IE:

var meta = document.createElement('meta');
meta.setAttribute('http-equiv', 'imagetoolbar');
meta.setAttribute('content', 'no');
document.getElementsByTagName('head')[0].appendChild(meta);

Even though <META HTTP-EQUIV="imagetoolbar" CONTENT="no"> does suppress
the image toolbar.

--
Grant Wagner <>
comp.lang.javascript FAQ - http://jibbering.com/faq


 
Reply With Quote
 
J1C
Guest
Posts: n/a
 
      05-24-2005
great - thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
lucene: add a field to index, based on html meta tag Keith Beef Java 0 10-23-2007 01:48 AM
Meta-Meta-Programming Erik Veenstra Ruby 29 02-08-2006 08:22 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Meta methods to govern meta data? Duane Johnson Ruby 6 10-28-2005 03:57 AM
META NAME and META HTTP-EQUIV Nym Pseudo HTML 1 09-26-2003 09:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57