我希望获得Web浏览器的实时屏幕分辨率作为用户RESTORE DOWN或MAXIMIZE而不刷新页面。
Are you using jQuery? If yes, then the code below should work
$(window).resize(function(){
var windowWidth = $(window).width();
var windowHeight = $(window).height();
// windowWidth & windowHeight are automatically updated when the browser size is modified
});
Not entirely sure what you're after, but here are some suggestions.
window.screen
contains the current OS resolution. That is accessible via screen.height
and screen.width
. Two other interesting values might be availHeight
and availWidth
(not 100% sure about the cross-browser availabilty there)
If you need to know the current browser-dimensions, that is stored on the window
object itself. window.innerHeight
, window.outerHeight
, window.innerWidth
and window.outerWidth
are the values of interest there. The inner prefixed values do reflect the working(client) area of the browser, whereas the outer prefixes contain the whole browser window area.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.