如何在不使用 jquery append 的情况下插入元标记? [英] How to insert metatag without using jquery append?
本文介绍了如何在不使用 jquery append 的情况下插入元标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下 jquery 将元标记插入到 html 文档中.
I used the following jquery to insert a metatag into a html document.
<script type="text/javascript">
if(screen.width>=320 && screen.width<=767){
$('head').append('<meta id="viewport" name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">');}
</script>
如果可能,我想在不使用 jquery 的情况下插入元标记.有人知道我该怎么做吗?
我相信我可能需要使用 document.getElementByTagName 但我不确定如何使用.
I believe I will probably need to use document.getElementByTagName but I'm not sure how.
以防万一您想知道,我将元标记插入到我的 html 中,以优化站点以使用 iphone 查看.不幸的是,width=device-width 不是一个选项,因为它不适用于我的 ipad 版本.
Just in case you are wondering, I am inserting the metatag into my html to to optomize the site for viewing with the iphone. Unfortunately, width=device-width is not an option as it doesn't play well with my ipad version.
推荐答案
var viewPortTag=document.createElement('meta');
viewPortTag.id="viewport";
viewPortTag.name = "viewport";
viewPortTag.content = "width=320, initial-scale=1.0, maximum-scale=1.0, user-scalable=0";
document.getElementsByTagName('head')[0].appendChild(viewPortTag);
这篇关于如何在不使用 jquery append 的情况下插入元标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文