Windows Phone screen height in PhoneGap app not 100%

后端 未结 4 1027
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 12:48

I\'m developing a Windows Phone app using PhoneGap/Cordova (though, I believe the problem I\'m having makes the fact that it\'s PhoneGap irrelevant). No matter what I seem t

相关标签:
4条回答
  • 2020-12-29 13:21

    I tried using device-height in the viewport meta tag, however I learned that IE doesn't support that tag. Then after my 100,000 google search, I found this page.

    After adding this to my CSS:

    @viewport{height:device-height}
    @viewport{width:device-width}
    @-ms-viewport{height:device-height}
    @-ms-viewport{width:device-width}
    

    and adding this to a JavaScript file that hits all of my pages:

    if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
        var msViewportStyle = document.createElement("style");
    
        msViewportStyle.appendChild(
            document.createTextNode(
                "@-ms-viewport{width:auto!important}"
            )
        );
    
        msViewportStyle.appendChild(
            document.createTextNode(
                "@-ms-viewport{height:device-height!important}"
            )
        );
    
        document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
    }
    

    Then my 100% body height started acting the way that I would expect it to.

    0 讨论(0)
  • 2020-12-29 13:26

    In your MainPage.xaml file, change

    shell:SystemTray.IsVisible="True"
    

    to

    shell:SystemTray.IsVisible="False"
    
    0 讨论(0)
  • 2020-12-29 13:27

    The overflow is a weird IE10 WebBrowser control thing. If you change the background color of the body you will see that both above and below your div are the background color.

    Here is a simple workaround:

    document.addEventListener("DOMContentLoaded", function () {
        var div = document.querySelector(".navbar_table_container");
        div.style.top = (div.offsetTop + div.offsetHeight + 4) + "px";
    });
    
    0 讨论(0)
  • 2020-12-29 13:40

    it seems that the key is width property in -ms-viewport, so a simpler solution would be:

    // put this in body or after body as it uses document.body.offsetWidth.
    if (/IEMobile\/10\.0/.test(navigator.userAgent)) {
        document.write('<style>@-ms-viewport { width: ' + document.body.offsetWidth + 'px; }</style>');
    }
    
    0 讨论(0)
提交回复
热议问题