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

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

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

相关标签:
19条回答
  • 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)

    0 讨论(0)
提交回复
热议问题