2014-02-22 41 views
2

我试图让Windows Phone的8 web应用程序,需要全屏幕分辨率查找屏幕分辨率在Windows Phone 8

看来是没有办法发现这个

使用:<meta name="viewport" content="width=device-width, user-scalable=no" />

这将永远是320

使用JavaScript screen.width返回320

页使用摹的JavaScript screen.availWidth返回320

我已经把一些代码,似乎是工作现在:

的JavaScript:

window.devicePixelRatio = window.devicePixelRatio || screen.deviceXDPI/screen.logicalXDPI; 
var actualWidth = screen.width * window.devicePixelRatio; 
actualWidth = actualWidth - (actualWidth % 2); 
var actualHeight = screen.height * window.devicePixelRatio; 
actualHeight = actualHeight - (actualHeight % 2); 

// TEMP FIX! 
if(actualHeight == 1282){ 
    actualHeight = 1280; 
} 

$(window).bind('resize', function() { 
    if(window.innerHeight > window.innerWidth){ 
     // portrait 
     width = actualWidth; 
     height = window.innerHeight; 
    }else{ 
     // landscape 
     width = actualHeight; 
     height = window.innerHeight; 
    } 

    $('html').css('width', width); 
    $('body').css('width', width); 
}).trigger('resize'); 

CSS:

@media screen and (orientation:portrait) { 
    @-ms-viewport { width: 720px; } 
} 
@media screen and (orientation:landscape) { 
    @-ms-viewport { width: 1280px; } 
} 

有没有更好的办法在Windows Phone 8上找到真正的屏幕分辨率?

任何关于这个问题的帮助/建议将不胜感激,谢谢!

回答

0

使用JavaScript,这段代码将在任何设备上运行:

var width = window.innerWidth; 
var height = window.innerHeight; 
+0

感谢您的回应,可惜这心不是答案 在一个HTC 8X(720x1280): 如果我用这个与视这给出320x521 如果我使用这个没有视口这给1024x1667 – Maverick

+0

哦,好的。谢谢你让我知道。 – jbakker