Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JQuery to add metadata in the Head Tag

Tags:

jquery

I'm trying to insert a new meta tag within the Head, I'm using a content managment system that won't allow editing within the Head so I'm attempting to do this using jQuery. Unfortunately I can't it to work.

This is the code I've added to the following webpage: http://www.newcastlegateshead.com

<script type="text/javascript"> 
$("head").append("<meta name=viewport content=width=400, initial-scale=0.45, minimum-    scale=0.45/><link rel=apple-touch-icon href=/images/customIcon.png/><meta name=apple-mobile-web-app-capable content=no /><meta name=apple-mobile-web-app-status-bar-style content=black-translucent /><link rel=apple-touch-icon-precomposed href=/images/customIcon.png/> ");
</script>
like image 857
Yippyj Avatar asked Jun 13 '12 15:06

Yippyj


People also ask

What is meta information in head tag?

Definition and Usage. The <meta> tag defines metadata about an HTML document. Metadata is data (information) about data. <meta> tags always go inside the <head> element, and are typically used to specify character set, page description, keywords, author of the document, and viewport settings.

Does meta tag have to be in head?

Defining MetadataThis element is always placed within the <head> section of the page. It cannot overlap the </head> closing tag. Note that <meta> is an empty element, and does not need a closing tag.


1 Answers

Try your code within

<script type="text/javascript"> 
     $(document).ready(function() {
         $("head").append("<meta name=viewport content=width=400, initial-scale=0.45, minimum-    scale=0.45/><link rel=apple-touch-icon href=/images/customIcon.png/><meta name=apple-mobile-web-app-capable content=no /><meta name=apple-mobile-web-app-status-bar-style content=black-translucent /><link rel=apple-touch-icon-precomposed href=/images/customIcon.png/> ");
    });
</script>

Short form of $(document).ready(function() {...}) is:

jQuery(function ($) {
    // Your code
})

This will ensure that you code will execute during onload.

like image 80
thecodeparadox Avatar answered Sep 20 '22 11:09

thecodeparadox