Размер окна просмотра, разрешения экрана и расположение курсора
Такой кроссбраузерный код поможет определить размер окна просмотра, разрешения экрана и расположение курсора. Эти данные могут быть полезны для использования с другими функциями JavaScript.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<script type="text/javascript"> function getViewportWidth() { if (window.innerWidth) { return window.innerWidth; } else if (document.body && document.body.offsetWidth) { return document.body.offsetWidth; } else { return 0; } } function getViewportHeight() { if (window.innerHeight) { return window.innerHeight; } else if (document.body && document.body.offsetHeight) { return document.body.offsetHeight; } else { return 0; } } var tellMeTheSizes=function() { document.getElementById("viewportwidth").innerHTML = getViewportWidth() + "px"; document.getElementById("viewportheight").innerHTML = getViewportHeight() + "px"; document.getElementById("resolutionheight").innerHTML = screen.height + "px"; document.getElementById("resolutionwidth").innerHTML = screen.width + "px"; } window.onload=function() { tellMeTheSizes(); } window.onresize=function() { tellMeTheSizes(); } window.onmousemove=function(event) { ev = event || window.event; document.getElementById("mousetop").innerHTML = ev.pageY + "px"; document.getElementById("mouseleft").innerHTML = ev.pageX + "px"; } </script> |