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

时间:2014-10-06 13:53:01

标签: javascript css html5 cordova windows-phone-8

我想在" index.html"中动态更改元标记视口在windows phonegap app上点击按钮。

我正在使用

  • Windows OS 8
  • phonegap 3.5
  • 使用Windows 8操作系统的设备诺基亚Lumia 1320

我想更改元标记

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

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

我已经尝试过以下网址,但是对于Windows手机没有任何效果。

how to set viewport so it is 380x800 or 800x380 depending on orientation?

Setting the Viewport to Scale to Fit Both Width and Height

在这里,我发现链接,它表示无法在winodws 8 OS中动态更改元标记

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

第一次编写简单函数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>

更多.. [1]:Can I change the viewport meta tag in mobile safari on the fly?