Connecting Tech Pros Worldwide Help | Site Map

Add meta tag

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 07:50 PM
J1C
Guest
 
Posts: n/a
Default Add meta tag

How can I programatically add meta tags with javascript?


  #2  
Old July 23rd, 2005, 07:50 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Add meta tag



J1C wrote:
[color=blue]
> How can I programatically add meta tags with javascript?[/color]

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/
  #3  
Old July 23rd, 2005, 07:52 PM
Grant Wagner
Guest
 
Posts: n/a
Default Re: Add meta tag

"J1C" <just1coder@yahoo.ca> wrote in message
news:1116251622.895823.132270@g44g2000cwa.googlegr oups.com...[color=blue]
> How can I programatically add meta tags with javascript?[/color]

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 <gwagner@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


  #4  
Old July 23rd, 2005, 08:01 PM
J1C
Guest
 
Posts: n/a
Default Re: Add meta tag

great - thanks!

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.