Android的不尊重元标记拆除? [英] Android not respecting metatag removal?

查看:112
本文介绍了Android的不尊重元标记拆除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个示例脚本从头部添加和删除元标记。但是Android 2.2似乎并不尊重它的去除。但是它确实尊重的点击,例如添加了元标记的..我怎么得到它尊重去除标签,并通过JavaScript还原到默认的视口?

 <脚本类型=文/ JavaScript的>

$(文件)。就绪(函数(){
传播initMeta(){
VAR headID = document.getElementsByTagName(头)[0];
VAR元节点= document.createElement方法(元);
metaNode.name ='视';
metaNode.content =WIDTH =设备的宽度,初始规模= 1.0,用户可扩展性=无,最小规模= 1.0,最大规模= 1.0;
metaNode.id =元标记;
headID.appendChild(元节点);}

功能closeMeta(){
$(#元标记)删除();}


$(#增)点击(函数(){initMeta();警报(元开);});
$(#删除)点击(函数(){closeMeta();警报(元闭);});

});

< / SCRIPT>

<输入名称=添加类型=按钮值=加元标记ID =添加/>
<输入名称=删除类型=按钮值=删除元标记ID =删除/>
 

解决方案

我注意到,在iOS的Safari浏览器这种行为了。

您实际上是去除meta标签(可验证通过DOM - 尝试提醒$(#元标记)的长度后取出。)

问题是视口本身不缺少的内容在该标签的响应。如果您更新内容或新的内容重新添加元标记,你应该看到它表现在屏幕上。但是,简单地删除元标记中,UA似乎认为没有变化必要的,因为它是没有得到任何明确的说明进行操作。

希望帮助!你的问题/例如帮助我实现这甚至有可能!

I created a sample script to add and remove metatags from the head. But Android 2.2 doesn't seem to respect it's removal. However it does respect the addition of the metatag on click for example.. How do I get it to respect the removal of the tag and revert to the default viewport through javascript?

<script type="text/javascript">

$(document).ready(function(){
function initMeta(){
var headID = document.getElementsByTagName("head")[0];         
var metaNode = document.createElement('meta');
metaNode.name = 'viewport';
metaNode.content = 'width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0';
metaNode.id = 'metatag';
headID.appendChild(metaNode);}

function closeMeta(){
$("#metatag").remove();}


$("#add").click(function(){initMeta();alert("meta opened");});
$("#del").click(function(){closeMeta();alert("meta closed");});

});

</script>

<input name="add" type="button" value="add metatag" id="add"/>
<input name="del" type="button" value="delete metatag" id="del"/>

解决方案

I note this behavior in iOS Safari too.

You are actually removing the meta tag (verifiable through DOM - Try alerting $("#metatag").length after removal)

The problem is the viewport itself does not respond to the absence of content in this tag. If you update the contents or re-add the meta tag with new contents, you should see it manifest on your screen. But by simply removing the meta tag, the UA seems to think "No change necessary" as it's not getting any explicit instructions there.

Hope that helps! Your question / example helped me realize this was even possible!

这篇关于Android的不尊重元标记拆除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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