Using jQuery to add metadata to the title tag

I am trying to insert a new meta tag in Head, I am using a content management system that will not allow editing in Head, so I am trying to do this with jQuery. Sorry, I canโ€™t work.

This is the code I 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> 
+9
source share
2 answers

Try your code in

 <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 $(document).ready(function() {...}) :

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

This will ensure that your code executes during onload .

+13
source

This worked for me ... thanks @thecodeparadox. To make it work, I needed single quotes, not double before and after

 <script type="text/javascript"> $(document).ready(function() { $("head").append('<meta name="apple-mobile-web-app-capable" content="yes">'); }); </script> 
0
source

Source: https://habr.com/ru/post/917993/


All Articles