By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,366 Members | 2,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,366 IT Pros & Developers. It's quick & easy.

Add meta tag

P: n/a
How can I programatically add meta tags with javascript?

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a

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 = "God";
meta.content = "Kibo";

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

See also

Martin Honnen
Jul 23 '05 #2

P: n/a
"J1C" <ju********> wrote in message
How can I programatically add meta tags with javascript?

In browsers that support it:

var meta = document.createElement('meta'); = 'author';
meta.content = 'Your Name';

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');

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

Grant Wagner <gw*****>
comp.lang.javascript FAQ -
Jul 23 '05 #3

P: n/a
great - thanks!

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.