JavaScript入門講座

Home > frameオブジェクト > lengthプロパティ

lengthプロパティ

frameオブジェクトのlengthプロパティはフレーム数を返します。

書式frames.length
対応Internet ExplorerFireFoxChromeSafariOpera
フレーム数
使用例フレーム数を表示する。

//-------親フレーム:index.html
<html>
<head>
<title>JavaScript frame length</title>
</head>
<frameset cols="150,*">
	<frame src="menu.html" name="menu">
		<frameset rows="20%,80%">
		<frame src="title.html" name="title">
		<frame src="page1.html" name="page">
	</frameset>
</frameset>
</html>

//-------メニュー:menu.html
<html>
<head>
<title>menu</title>
<script type="text/javascript">
function dispLength(){
        alert(parent.frames.length);
}
</script>
</head>
<body>
<h1>メニュー</h1>
<form>
フレーム数を表示する
<input type="button" value="確認" onClick="dispLength()">
</form>
</body>
</html>

//-------タイトル:title.html
<html>
<head>
<title>title</title>
</head>
<body>
<h1>タイトル</h1>
</body>
</html>

//-------ページ:page1.html
<html>
<head>
<title>page1</title>
</head>
<body>
<h1>ページ1</h1>
</body>
</html>
						
関連メンバ
framesフレーム配列
nameフレーム名
parent現在のフレームの親フレーム
self現在のフレーム自身