javascript:find screen resolution when having multiple monitors
I am using this piece of code to determine the client screen resolution, and then logging it
<input type="hidden" id="DFF63C7E-FB32-49AE-8ADA-3AB5C4834FB0" name="DFF63C7E-FB32-49AE-8ADA-3AB5C4834FB0"/>
<input type="hidden" id="565C07CF-0D37-41DE-B47D-A247E9BD231B" name="565C07CF-0D37-41DE-B47D-A247E9BD231B" />
<script type="text/javascript" language="javascript">
document.getElementById("DFF63C7E-FB32-49AE-8ADA-3AB5C4834FB0").value = screen.width;
document.getElementById("565C07CF-0D37-41DE-B47D-A247E9BD231B").value = screen.height;
</script>
It worked OK when testing in my localhost, but what I found out from the production logs was that the screen resolution was always 480x640. Does anyone know why this happens ?
And I did some more digging and found that I could change the resolution of my primary monitor and regardless of whether I open my browser in primary/secondary monitor, it would always give me the resolution of the primary monitor.
Is there any way to get the screen resolution based on which monitor the browser gets opened ?
And obviously the next question is, if the resolution changes midway (say from control panel) or moving the browser from one to another, is there a way to detect/update it with JS ?
Add the following line to your page.
window.moveTo(0,0); window.resizeTo(screen.availWidth,screen.availHeight);"
it will resize your window to full width and height..
for example use
<body onload="window.moveTo(0,0); window.resizeTo(screen.availWidth,screen.availHeight);" >
试试这个来获得窗口的尺寸:
window.document.width //Get the width
window.document.height //Get the height
链接地址: http://www.djcxy.com/p/58368.html