JavaScriptでは、外側の幅と外側のハイトを使用して、ブラウザのサイズを取得できます。内部幅と内側のハイトを使用して、ウィンドウのサイズを取得します(ブラウザの境界部分を除く)。 IE6および以前のバージョンの場合、標準モードか混合モードかを区別する必要があります。標準モードでは、document.documentlement.clientwidth、document.documentelement.clientheightを使用します。無差別モードでは、document.bodyのclientWidth、clientheightを使用します。
コードコピーは次のとおりです。
(関数 () {
var pagewidth = window.innerwidth;
var pageheight = window.innerheight;
var broswerwidth = window.outerwidth;
var broswerheight = window.outerheight;
アラート(pageWidth + "" + pageheight);
アラート(broswerwidth + "" + broswerheight);
if(typeof pagewidth!= "number"){
if(document.compatmode == "css1compat"){//標準モード
pagewidth = document.documentelement.clientWidth;
pageheight = document.documentelement.clientheight;
} それ以外 {
pageWidth = document.body.clientWidth;
pageheight = document.body.clientheight;
}
}
})();
ウィンドウの位置を取得します。つまり、Chrome、Safari、ScreenLeft、Screentopを使用して、画面の左側と上部から窓の位置を取得します。 Firefoxはこのプロパティをサポートしていません。 FirefoxはScreenXPとScreenyを使用して同じ効果を達成します。
コードコピーは次のとおりです。
(function btnfun(){
var leftpos =(typeof windof.screenleft == "number")? window.screenleft:
window.screenx;
var toppos =(typeof windof.screentop == "number")? window.screentop:
window.screeny;
アラート(leftpos + "" + toppos);
//alert(window.screenleft+ ""+window.screentop);
})();