简体   繁体   English

Noscript块内的元视口标签

[英]Meta viewport tag inside noscript block

I have an iPhone web application that creates a "meta viewport" tag dynamically, using Javascript, depending on certain user-configured settings. 我有一个iPhone Web应用程序,它使用Javascript根据某些用户配置的设置动态创建“元视口”标签。

I want to provide a default meta viewport tag in case Javascript is disabled, but can't find a proper way to do it. 我想提供一个默认的meta视口标签,以防Javascript被禁用,但是找不到正确的方法。

I tried this: 我尝试了这个:

<noscript>
<meta name="viewport" content="initial-scale=1.0">
</noscript>

And it does work, however it does not seem to be valid, as noscript is apparently not allowed in the HEAD section of an HTML document (I also looked at this question ) 它确实有效,但是它似乎无效,因为在HTML文档的HEAD部分中显然不允许使用noscript (我也看过这个问题

Any alternatives? 有其他选择吗?

Edit: 编辑:

I already tried having a default meta viewport tag, then removing (or replacing) it with Javascript. 我已经尝试过使用默认的元视口标签,然后将其删除 (或替换为Javascript)。 This "almost" works: You can indeed modify an existing viewport meta tag with Javascript (the technique is well described here ). 这种“几乎”的工作原理:您确实可以使用Javascript修改现有的视口元标记(该技术在此处进行了很好的描述)。 However there are some limitations: While you can modify the value of a given property, you can NOT make the device "forget" (reset to default value) a property that has already been defined. 但是,存在一些限制:尽管可以修改给定属性的值,但不能使设备“忘记”(重置为默认值)已定义的属性。 Also, simply removing the meta tag with Javascript doesn't work. 此外,仅使用Javascript删除meta标签也不起作用。

Tricky. 棘手。

Have you tried 你有没有尝试过

<meta name="viewport" content="initial-scale=1.0">

<script>
document.write('<meta name="viewport" content="initial-scale=2.0">');
</script>

? (2.0 being the scale than you would want to set if scripting is enabled) (2.0是比例尺,如果启用了脚本,则要设置的比例尺)

I can't find any binding info on whether this is legal, but it seems to be in HTML. 我找不到关于这是否合法的任何绑定信息,但似乎在HTML中。 The question is whether it'll be parsed correctly. 问题是是否可以正确解析它。

Other than that, I can think of only two alternatives: 除此之外,我只能想到两种选择:

  • Detecting Javascript support on server side, and serving two different pages, one with, one without the meta tag 在服务器端检测Javascript支持,并提供两个不同的页面,其中一个带有,而一个不带有meta标签

  • Always embedding the viewport tag, and removing it using Javascript - I have no idea whether this'll work, though. 始终嵌入视口标签,并使用Javascript 删除它-不过我不知道这是否行得通。

You could use HTML5. 您可以使用HTML5。 In HTML5 <noscript> is permitted as a child of head, and <meta> is permitted as a child of noscript. 在HTML5中,允许<noscript>作为<noscript>的子级,而允许<meta>作为noscript的子级。

See here: http://dev.w3.org/html5/spec/scripting-1.html#the-noscript-element 参见此处: http : //dev.w3.org/html5/spec/scripting-1.html#the-noscript-element

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM