Get the size of the screen, current web page and browser window

前端 未结 19 2433
面向向阳花
面向向阳花 2020-11-21 05:29

How can I get windowWidth, windowHeight, pageWidth, pageHeight, screenWidth, screenHeight,

19条回答
  •  猫巷女王i
    2020-11-21 06:33

    With the introduction of globalThis in ES2020 you can use properties like.

    For screen size:

    globalThis.screen.availWidth 
    globalThis.screen.availHeight
    

    For Window Size

    globalThis.outerWidth
    globalThis.outerHeight
    

    For Offset:

    globalThis.pageXOffset
    globalThis.pageYOffset
    

    ...& so on.

    alert("Screen Width: "+ globalThis.screen.availWidth +"\nScreen Height: "+ globalThis.screen.availHeight)

提交回复
热议问题