JavaScriptでモーダルダイアログ


showModalDialogメソッドでモーダルダイアログを実現できる。


Modal.html

<html>
<head>
<script>
function showModal(){
        //モーダルでreturn.htmlを起動し、戻り値を取得
	var value = showModalDialog('return.html');
	alert(value);
}
</script>
</head>
<body>
<input type='button' value='開く' onclick='showModal()'/>
</div>

</body>
</html>


return.html

<html>
<head>
<script>
function closeWindow(){
        //戻り値を設定し閉じる
	window.returnValue = '123';
	window.close();
}
</script>
</head>
<body>
<input type='button' value='りたーん' onclick='closeWindow()'/>
</div>

</body>
</html>

※IE6sp2は動作確認済み。ただ、FireFox2.0ではなぜか動かなかった。

追記:showModalDialog は Firefox 3.0からの機能らしい。


参考にしたサイト

http://amachang.art-code.org/shibuyajs24/