今天写了个DEMO测试下window.open()返回值可是在IE和遨游下都能跑起来可是到了FF里就死活不行。找了半天终于解决了现在把源代码贴出来希望大家以后少写弯路。
【父窗口】
<script>
function show_child()
{
var child=window.open("child.html","child","height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
/* if(!child.closed)
{
if(!window.close())
{
var textValue = frm.txt.value; parent.frm0.txt0.value = textValue;
}
else
{
window.close();
child.close();
}
}*/
}
</script>
<a href="javascript:show_child();">打开子窗口</a>
<form name=frm0>
<input type="text" name="txt0" id="txt0"> //注意这里一定要写ID属性不然FF下取不到值
</form>
【子窗口】
<script>
function choseItem()
{
var v="";
var check_item = document.frm.item;
for(i=0;i<check_item.length;i++)
{
if(check_item[i].checked)
{
v+=","+check_item[i].value;
}
document.frm.txt.value=v.replace(/^,{1}/,"");
}
}
function foo()
{
window.close();
window.opener.document.getElementById("txt0").value=document.getElementById("txt").value
}
</script>
<body>
<form name=frm>
<input type=checkbox name=item value=1 onclick="choseItem();">a
<input type=checkbox name=item value=2 onclick="choseItem();">b
<input type=checkbox name=item value=3 onclick="choseItem();">c
<input type=checkbox name=item value=4 onclick="choseItem();">d
<input type=text name="txt" id="txt">
</form>
<input type=button value="关闭" onclick="foo();">
</body>
1969

被折叠的 条评论
为什么被折叠?



