JavaScriptプログラムに関する各種メモ書き

JavasScriptでウィンドウの幅、高さを取得する。

//-------------------------------- get_browser_width
function get_browser_width() {
	if ( window.innerWidth ) { return window.innerWidth; }  
	else if ( document.documentElement && document.documentElement.clientWidth != 0 ) { return document.documentElement.clientWidth; }  
	else if ( document.body ) { return document.body.clientWidth; }  
	return 0;  
}
//-------------------------------- get_browser_height
function get_browser_height() {
	if ( window.innerHeight ) { return window.innerHeight; }  
	else if ( document.documentElement && document.documentElement.clientHeight != 0 ) { return document.documentElement.clientHeight; }  
	else if ( document.body ) { return document.body.clientHeight; }  
	return 0;  
}

参考:http://d.hatena.ne.jp/onozaty/20060802/p1

参考:http://www.sasaraan.net/program/js/jswndstate.html

No.511
04/05 17:03

edit