In Javascript, you can use OuterWidth and OuterHeight to get the size of the browser. Use innerWidth and innerHeight to get the size of the window (excluding the browser border part). For IE6 and previous versions, it is necessary to distinguish whether it is a standard mode or a mixed mode. The standard mode uses document.documentElement.clientWidth, document.documentElement.clientHeight; the promiscuous mode uses document.body's clientWidth, clientHeight.
The code copy is as follows:
(function () {
var pageWidth = window.innerWidth;
var pageHeight = window.innerHeight;
var broswerWidth = window.outerWidth;
var broswerHeight = window.outerHeight;
alert(pageWidth + " " + pageHeight);
alert(broswerWidth + " " + broswerHeight);
if (typeof pageWidth != "number") {
if (document.compatMode == "CSS1Compat") { //The standard mode
pageWidth = document.documentElement.clientWidth;
pageHeight = document.documentElement.clientHeight;
} else {
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
}
}
})();
Get the location of the window: IE, chrome, Safari, use screenLeft, screenTop to get the location of the window from the left and upper side of the screen. Firefox does not support this property. Firefox uses screenXP and screenY to achieve the same effect.
The code copy is as follows:
(function btnFun() {
var leftPos = (typeof window.screenLeft == "number") ? window.screenLeft :
window.screenX;
var topPos = (typeof window.screenTop == "number") ? window.screenTop :
window.screenY;
alert(leftPos + " " + topPos);
//alert(window.screenLeft+" "+window.screenTop);
})();