弹出窗口根据内容自动调整大小的JS解决方案

本文介绍了一个父窗体打开子窗体并通过JavaScript实现数据传递和响应的示例。具体包括如何调整子窗体大小、传递文本值以及在子窗体关闭时更新父窗体的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

父类(主/打开)窗口中代码为:

 

 

 

<html>
<head><title>父类窗口</title>
<script type="text/javascript">
var s,oRes;
 
function openwin(url)
 
{
     s
=window.open("child.htm");    
    oRes
=s.document.getElementById("txt");
    
//文本改变时还回
    //oRes.onchange=function(){
    //alert("text changed");
    //document.getElementById("txtRet").value=oRes.value;}
    //子窗口关闭时还回,另一种方法传参数
    //var btnChild=s.document.getElementById("btnSubmit");
    //btnChild.onclick=function(){
    //alert("btn clicked");
    //document.getElementById("txtRet").value=oRes.value;}
 }

 
function childclose(txt)
{
    document.getElementById(
"txtRet").value=txt;
}

</script>
<body>
<form>
<input type="text" id="txtRet" name="txtRet" />
<input type="button" value="按钮" onclick="openwin('child.htm')" />
</form>
</body>
</html>

 

在之类弹出窗口加入resizeto(window.clientWidth,window,clientHeight)代码:

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    
<title>子类窗口</title>
    
<script type="text/javascript">
    window.open
=function() {
        
if(window.opener)
            
{
           width
=document.body.clientWidth+33;
           height
=document.body.clientHeight+50;
           window.resizeTo(width,height);
       }

    }
    
    
</script>
</head>
<body style="margin:0px;" onload="win_onLoad()">
<input type="text" id="txt" name="txt" />
<input type="button" id="btnSubmit" name="btnSubmit" value="确定" />
<script type="text/javascript">
btnSubmit.onclick
=function(){
        
if(window.opener)
        
{
            window.opener.childclose(document.getElementById(
"txt").value);
            window.setTimeout(
function(){self.close();},500);
        }

        
else
        
{
            self.close();
        }

    }

</script>
</body>
</html>

 

 referrence:http://topic.csdn.net/t/20040623/09/3114967.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值