简体   繁体   English

在Windows Phonegap应用程序中页面加载后如何动态更改元标记视口?

[英]How to dynamically change meta tag viewport after page load in windows phonegap application?

I want to dynamically change meta tag viewport in "index.html" in windows phonegap app on button click. 我想在按钮单击Windows Phonegap应用程序的“ index.html”中动态更改元标记视口。

I am using 我在用

  • Windows OS 8 Windows OS 8
  • phonegap 3.5 phonegap 3.5
  • Device Nokia Lumia 1320 with windows 8 OS 带有Windows 8 OS的设备Nokia Lumia 1320

I want to change below meta tag 我想在元标记下方进行更改

<meta id="viewport" name="viewport" content="width=device-width">

to

<meta id="viewport" name="viewport" content="width=720">

I have already tried below URLs but nothing worked for windows phone. 我已经尝试过以下URL,但对Windows Phone无效。

how to set viewport so it is 380x800 or 800x380 depending on orientation? 如何将视口设置为380x800或800x380(取决于方向)?

Setting the Viewport to Scale to Fit Both Width and Height 将视口设置为缩放以适合宽度和高度

Here I found link where it says it is not possible to change meta tag dynamically in winodws 8 OS 在这里,我找到了链接,该链接说不可能在winodws 8 OS中动态更改元标记

http://www.quirksmode.org/blog/archives/2011/06/dynamically_cha.html http://www.quirksmode.org/blog/archives/2011/06/dynamically_cha.html

尝试检测设备/操作系统并相应地更改元标记http://www.sitepoint.com/detect-mobile-devices-jquery/

1st write simple function JavaScript for example I have written one function viewport() 第一个编写简单的函数JavaScript,例如,我编写了一个函数viewport()

<html> 
<head>
    <script>
        function viewport(){
            var msViewportStyle = document.createElement("style");

            msViewportStyle.appendChild(
                document.createTextNode(
                    "@-ms-viewport{width:auto!important;zoom:1!important;}"
                )
            );

            msViewportStyle.appendChild(
                document.createTextNode(
                    "@-ms-viewport{height:auto!important}"
                )
            );

            document.getElementsByTagName("head[0].appendChild(msViewportStyle);
        }
    </script>
</head>
<body>
<button id="btnSubmit" onclick="viewport();">changeviewport</button>
</body>

more..[1]: Can I change the viewport meta tag in mobile safari on the fly? 更多.. [1]: 我可以即时更改移动Safari中的视口元标记吗?

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

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