使用JQuery在Head标记中添加元数据 [英] Using JQuery to add metadata in the Head Tag

查看:67
本文介绍了使用JQuery在Head标记中添加元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Head内插入新的meta标签,我正在使用内容管理系统,该系统不允许在Head内进行编辑,因此我尝试使用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.

这是我添加到以下网页中的代码: http://www.newcastlegateshead.com

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>

推荐答案

在内部尝试代码

<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>

$(document).ready(function() {...})的简写形式是:

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

这将确保您的代码将在 onload期间执行. .

This will ensure that you code will execute during onload.

这篇关于使用JQuery在Head标记中添加元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆