2016-02-08 71 views
7

我有一個雙顯示器設置不同的屏幕分辨率,當我在Chrome瀏覽this page它顯示兩個屏幕右側resoltion。但IE只顯示我的主屏幕的分辨率。它看起來比IE window.screen.availWidthwindow.screen.availHeight只返回主屏幕的值。 我可以獲得運行Internet Explorer的第二個屏幕的屏幕分辨率嗎?Window.screen在Internet Explorer和多臺顯示器

+0

哪個版本,我們談論的,最小的支持版本等。 – Tschallacka

+0

IE8(IE11在IE8模式)將是巨大的,但只是IE11將被罰款了。 –

回答

4

使用在http://archive.cpradio.org/code/javascript/dual-monitors-and-windowopen/

function FindLeftWindowBoundry() 
 
{ 
 
\t // In Internet Explorer window.screenLeft is the window's left boundry 
 
\t if (window.screenLeft) 
 
\t { 
 
\t \t return window.screenLeft; 
 
\t } 
 
\t 
 
\t // In Firefox window.screenX is the window's left boundry 
 
\t if (window.screenX) 
 
\t \t return window.screenX; 
 
\t \t 
 
\t return 0; 
 
} 
 

 
window.leftWindowBoundry = FindLeftWindowBoundry; 
 

 
// Find Left Boundry of the Screen/Monitor 
 
function FindLeftScreenBoundry() 
 
{ 
 
\t // Check if the window is off the primary monitor in a positive axis 
 
\t // X,Y     X,Y     S = Screen, W = Window 
 
\t // 0,0 ---------- 1280,0 ---------- 
 
\t //  |   |   | ---  | 
 
\t //  |   |   | | W | | 
 
\t //  |  S |   | --- S | 
 
\t //  ----------   ---------- 
 
\t if (window.leftWindowBoundry() > window.screen.width) 
 
\t { 
 
\t \t return window.leftWindowBoundry() - (window.leftWindowBoundry() - window.screen.width); 
 
\t } 
 
\t 
 
\t // Check if the window is off the primary monitor in a negative axis 
 
\t // X,Y     X,Y     S = Screen, W = Window 
 
\t // 0,0 ---------- -1280,0 ---------- 
 
\t //  |   |   | ---  | 
 
\t //  |   |   | | W | | 
 
\t //  |  S |   | --- S | 
 
\t //  ----------   ---------- 
 
\t // This only works in Firefox at the moment due to a bug in Internet Explorer opening new windows into a negative axis 
 
\t // However, you can move opened windows into a negative axis as a workaround 
 
\t if (window.leftWindowBoundry() < 0 && window.leftWindowBoundry() > (window.screen.width * -1)) 
 
\t { 
 
\t \t return (window.screen.width * -1); 
 
\t } 
 
\t 
 
\t // If neither of the above, the monitor is on the primary monitor whose's screen X should be 0 
 
\t return 0; 
 
} 
 

 
window.leftScreenBoundry = FindLeftScreenBoundry; 
 

 
console.log(window.screen.width); 
 
console.log(window.leftScreenBoundry()); 
 

 
console.log(window.screen.height);

發現我知道這是沒有太大的古代碼,但它至少可以讓您評估,如果客戶端是一個雙顯示器設置,並有多寬上集合是。

唯一的F *編了事情IE瀏覽器是均勻分佈的所有montors之間的分辨率。

因此,需要的總的寬度和通過監視器的數目除以它。

我有3個顯示器,2個在1920 x 1080,一個在1600 x 900爲我的測試和IE瀏覽器給左邊的位置1745 0 -1745所以是...一切都與IE關閉,但希望這一小段代碼將幫助你,或者其他人進一步爲IE做出半兼容的代碼。

+0

我已經找到該代碼,我無法使用它。我的左屏幕是1600x900,我的右屏幕1920x1080。正確的屏幕是我的主屏幕。 'window.leftScreenBoundry()'返回-1920,這超出了我的桌面。 –

+0

也一樣。與監視器的排序等有關。對此你沒有太多的辦法。你試圖達到什麼目標? – Tschallacka

+0

調整窗口大小。我有幾個動態元素,這使我無法讓IE處理窗口大小。 –