Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add meta tag to <head>

    Hi
    I have been struggling with this for a while, Iv seen the solutions posted here.
    How do I append some HTML into the HEAD tag?

    That didnt work
    The code is added to the oScript element but thats it.
    I have tried another script from here:

    How to impressing code line in 'head' tag?

    I want to add a meta tag from the body tag and it worked using Jscript

    This worked only on my local but not on hoster:

    Code:
        HtmlMeta GoogleVerify = new HtmlMeta();
        GoogleVerify.Name = "verify-v1";
        GoogleVerify.Content = "681rsArfYmoRz88BIT8ZVDeLk4b6VMEn1+StcF61iwY=";
        HtmlHead head = (HtmlHead)Page.Header;
        head.Controls.Add(GoogleVerify);
    And on the hoster theres a scripting error as well

    why innerHTML doest work?

  • #2
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Due to the lack of responses I assume that if the aforesaid solutions didnt work then theres no other way to do it.

    Iv'e tried all the other suggestions adding the links but to no avail.
    They dont work on any browser

    I guess this is where we admit defeat

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts
    Works in FF3 and IE7:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title></title>
    </head>
    <body>
    <script type="text/javascript">
    //- <![CDATA[
    var yourTag=document.createElement('meta');
    yourTag.name = "myTag";
    yourTag.content = "ohYEAH";
    document.getElementsByTagName('head')[0].appendChild(yourTag);
    // and check if it works
    for (i=0;i<document.getElementsByTagName('meta').length;i++){
    document.write(document.getElementsByTagName('meta')[i].content+'<br />');
    }
    //- ]]>
    </script>
    </body>
    </html>
    Last edited by freedom_razor; 03-12-2009 at 10:02 AM. Reason: Moved code to BODY.

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi
    Thanx for your post.
    Your script works and I see the meta tags including the new one are written on the page yet the new tag is not in the <head>

    This happened to me with the previous examples as well. The new tag is added to the <head> object child array but is not added into the page..

    Is there a pre-document-init event in js?
    Maybe the reason is that when the script is parsed the head has already been loaded..??

    BTW the script writes in ff yet ie has a syntax error..

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by safhac View Post
    Hi
    Maybe the reason is that when the script is parsed the head has already been loaded..??
    I guess that is it. And is there not possibly a security aspect?

  • #6
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts
    Code I posted didn't throw any errors in IE7. But it wasn't working well in IE either, because NAME attribute wasn't included in new META tag in IE.
    I've corrected this now, and you can see that the new META tag is in HEAD section:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title></title>
    </head>
    <body>
    <script type="text/javascript">
    //- <![CDATA[
    var yourTag=document.createElement('meta');
    window.getSelection ? yourTag.name='your name' : yourTag.Name='your name' //all lower-case doesn't work in IE7, and only all-lowercase works in FF
    yourTag.content='your content';
    document.getElementsByTagName('head')[0].appendChild(yourTag);
    alert('Contents of HEAD section:'+document.getElementsByTagName('head')[0].innerHTML);
    //- ]]>
    </script>
    </body>
    </html>
    If you hoping to see that META in source code of the page you'll have to open a new document and fill it with contents of the page+that new META tag. Usually, if page is modified client-side, the changes aren't reflected in the source code you view with your browser, though they are applied to the document.

    Can I ask you what possible use you see for adding META tags client-side?

  • #7
    Regular Coder Actinia's Avatar
    Join Date
    Feb 2007
    Location
    Essex, UK
    Posts
    250
    Thanks
    1
    Thanked 23 Times in 22 Posts
    I tried this in FF using the Web Developer toolbar. This lets you view the generated code (View Source, View Generated Code), which indeed shows the generated meta tag just before the closing </head>. The Developer Toolbar in IE7 also shows it.

    John

  • Users who have thanked Actinia for this post:

    freedom_razor (03-14-2009)

  • #8
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanx freedom_razor

    The script is working perfectly both in IE and FF

    I can see it with firebug but not in source..

    I wanted to index my video sharing blog in google

    Ive asked one of the blog developers and he said thats impossible

    but if i can get it to work using script then fine

    so the script you wrote works but google doesnt verify it for indexing

    I have to find another way..

  • #9
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts
    What do you mean, your blog doesn't come up at all? How old is the domain?

    Also, Javascript is a client-side technology, it is not going to help you at all with Google. It works in your browser. Bots reach documents on the server but usually don't execute Javascript in them.

    Why don't you just put META in the source? You have no access to it?

  • #10
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no i dont

    if i did then there weer no problem..

    youre right i got to have server side code to add it with script thats why the jscript worked in the 1st example..

    Cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •