2014-02-22 44 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