Add meta tag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J1C

    Add meta tag

    How can I programatically add meta tags with javascript?

  • Martin Honnen

    #2
    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.creat eElement &&
    (meta = document.create Element('meta') )) {
    // set properties
    meta.name = "God";
    meta.content = "Kibo";

    // now add the meta element to the head
    document.getEle mentsByTagName( 'head').item(0) .appendChild(me ta);
    }

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


    --

    Martin Honnen

    Comment

    • Grant Wagner

      #3
      Re: Add meta tag

      "J1C" <just1coder@yah oo.ca> wrote in message
      news:1116251622 .895823.132270@ g44g2000cwa.goo glegroups.com.. .[color=blue]
      > How can I programatically add meta tags with javascript?[/color]

      In browsers that support it:

      var meta = document.create Element('meta') ;
      meta.name = 'author';
      meta.content = 'Your Name';
      document.getEle mentsByTagName( 'head')[0].appendChild(me ta);

      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.create Element('meta') ;
      meta.setAttribu te('http-equiv', 'imagetoolbar') ;
      meta.setAttribu te('content', 'no');
      document.getEle mentsByTagName( 'head')[0].appendChild(me ta);

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

      --
      Grant Wagner <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq


      Comment

      • J1C

        #4
        Re: Add meta tag

        great - thanks!

        Comment

        Working...