How can I get the current height and width of the available space in the browser as it is open?
I do not want the height of the total document, just look at the screen.
You can take a look at this method to see it.
and alert that function to
in less () {var myWidth = 0, myHeight = 0; If (type window.innerWidth == 'number') {// non-IE myWidth = window.innerWidth; MyHeight = window.innerHeight; } And if (document.documentElement & amp; amp; document.documentElement.clientWidth || document.documentElement.clientHeight)) {// IE 6+ in 'standard compatible mode' myWidth = document.documentElement.clientWidth; MyHeight = document.documentElement.clientHeight; } And if (document.body & amp; (document.body.clientWidth || document.body.clientHeight)) {// IE4 compatible myWidth = document.body.clientWidth; MyHeight = document.body.clientHeight; } Window.alert ('width =' + myWidth); Window.alert ('height =' + myHeight); }
It should also be noted that most of the JS framework (jquery, ext, prototype) will provide a function to do so.
In jQuery:
$ (window). With (); $ (Window) .height ();
No comments:
Post a Comment