Get window Size
The code is as follows |
Copy Code |
var pagewidth = window.innerwidth, var pageheight = window.innerheight; if (typeof pagewidth!= "number") { if (Document.compatmode = = "Number") { PageWidth = Document.documentElement.clientWidth; PageHeight = Document.documentElement.clientHeight; }else{ PageWidth = Document.body.clientWidth; PageHeight = Document.body.clientHeight; } } |
We first paid the values of Window.innerwidth and Window.innerheight to PageWidth and PageHeight respectively. Then check that the PageWidth is not a numeric value, or, if not, document.compatmode to determine if the page is in standard mode. If so, the values of Document.documentElement.clientWidth and document.documentElement.clientHeight are used respectively. Otherwise, the values of Document.body.clientWidth and document.body.clientHeight are used.
Get window Position
The code is as follows |
Copy Code |
var leftpos = (typeof Window.screenleft = "number")? Window.screenLeft:window.screenX; var toppos = (typeof window.screentop = "number")? Window.screenTop:window.screenY; |
These two examples are intended to take the position of the left and the top of the window, first using the two-dollar operator to determine whether the Screenleft property and the Screentops attribute exist, and, if present (in IE, Safari, opera, and Chrome), the values of the two properties. If it does not exist (in Firefox), take the values of Screenx and Screeny.