How to get document height and width without using jquery

后端 未结 10 1748
有刺的猬
有刺的猬 2020-11-28 05:26

How to get document height and width in pure javascript i.e without using jquery.
I know about $(document).height() and $(document).width(), bu

10条回答
  •  时光说笑
    2020-11-28 05:45

    Even the last example given on http://www.howtocreate.co.uk/tutorials/javascript/browserwindow is not working on Quirks mode. Easier to find than I thought, this seems to be the solution(extracted from latest jquery code):

    Math.max(
        document.documentElement["clientWidth"],
        document.body["scrollWidth"],
        document.documentElement["scrollWidth"],
        document.body["offsetWidth"],
        document.documentElement["offsetWidth"]
    );
    

    just replace Width for "Height" to get Height.

提交回复
热议问题