codelibのjavaScriptの親子窓口問題2
5569 ワード
2.window.show ModalDialog()
vReturnValue=window.show ModalDialog(s URL[,vAgments][,s Feature])
vAgments親ウィンドウからサブウィンドウにパラメータを転送します.
VReturn Valueサブウィンドウは親ウィンドウにデータを転送します.
父の窓口
vReturnValue=window.show ModalDialog(s URL[,vAgments][,s Feature])
vAgments親ウィンドウからサブウィンドウにパラメータを転送します.
VReturn Valueサブウィンドウは親ウィンドウにデータを転送します.
父の窓口
<div id="popup_2" align="center"><hr>
<fieldset><legend>window.showModalDialog()</legend>
<p><label for="name_2"> :</label> <input type="text" name="name_2"></p>
<p><label for="age_2"> :</label> <input type="text" name="age_2"></p>
<p><label for="sex_2"> :</label> <input type="text" name="sex_2"></p>
<p><label for="dep_2"> :</label> <input type="text" name="dep_2"></p>
<p><label for="pro_2"> :</label> <input type="text" name="pro_2"></p>
</fieldset>
<input type="button" class="button" onclick="showUserDialog(2)" value=" ">
</div>
親ウィンドウjsvar options = "location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=yes,toolbar=no,left=200,top=200,height=300,width=400";
var dialogOptions = "dialogWidth:400px;dialogHeight:300px;dialogLeft:350px;dialogTop:150px;center:no;help:no;resizable:no;status:no;scroll:no";
var legends = ["window.open()","window.showModalDialog()","window.showModelessDialog()"];
var title = "";
var arg_2 = new Object();
function showUserDialog(flag){
title = legends[flag - 1];
switch (flag) {
case 1:
window.open("inner_1.html","_blank",options);
break;
case 2:
arg_2.title = title;
arg_2.name_2 = document.all.name_2.value;
arg_2.age_2 = document.all.age_2.value;
arg_2.sex_2 = document.all.sex_2.value;
arg_2.dep_2 = document.all.dep_2.value;
arg_2.pro_2 = document.all.pro_2.value;
var res_2 = window.showModalDialog("inner_2.html",arg_2,dialogOptions);
if(typeof(res_2) == "object"){
document.all.name_2.value = res_2.name_2;
document.all.age_2.value = res_2.age_2;
document.all.sex_2.value = res_2.sex_2;
document.all.dep_2.value = res_2.dep_2;
document.all.pro_2.value = res_2.pro_2;
}
break;
case 3:
window.showModalDialog("inner_3.html",window,dialogOptions);
break;
default:
break;
}
}
子供の窓口<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script language="javascript" src="script/popupWindow.js"></script>
</head>
<body onload="init_2()">
<div align="center">
<fieldset>
<script language="javascript">
document.write("<legend>" + getTitle_2() + "</legend>");
</script>
<p><label for="name_2"> :</label> <input type="text" name="name_2"></p>
<p><label for="age_2"> :</label> <input type="text" name="age_2"></p>
<p><label for="sex_2"> :</label> <input type="text" name="sex_2"></p>
<p><label for="dep_2"> :</label> <input type="text" name="dep_2"></p>
<p><label for="pro_2"> :</label> <input type="text" name="pro_2"></p>
</fieldset>
<input type="button" value=" " onclick="handIn_2()" class="">
</div>
</body>
</html>
サブウィンドウjsfunction init_2(){
var inputArg = window.dialogArguments;
document.all.name_2.value = inputArg.name_2;
document.all.age_2.value = inputArg.age_2;
document.all.sex_2.value = inputArg.sex_2;
document.all.dep_2.value = inputArg.dep_2;
document.all.pro_2.value = inputArg.pro_2;
}
function handIn_2(){
var inputArg = new Object;
inputArg.name_2 = document.all.name_2.value;
inputArg.age_2 = document.all.age_2.value;
inputArg.sex_2 = document.all.sex_2.value;
inputArg.dep_2 = document.all.dep_2.value;
inputArg.pro_2 = document.all.pro_2.value;
window.returnValue = inputArg;
window.close();
}
function getTitle_2(){
var inputArg = window.dialogArguments;
return inputArg.title;
}