window.open() 打开的子页面 往主页面传参问题

国研兄弟遇到一个问题 问我我百度了下帮他解决了
下面是我参考的demo , 虽然不难不过以前没有遇到过这样的需求,就当多了解点姿势了。

<!--主页面的代码--><br><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="../../commonJS/jquery.js"></script>
 <script>
  
</script>
</head>
<body> 
<div style="width:140px; height:60px; position:relative;display:inline-block;background-color: red; margin-right:20px;display:inline-block;cursor: pointer;" id="addMatchSchedule"> </div>
  </body>
</html>
<script>
     
    $("#addMatchSchedule").click(function()
        {alert("a");
            window.open('child.html',"新增","width=500,height=480,screenX=400,screenY=100");
        }
    );
     
    //子页面调用的函数
    window.BBBB = function(){
         
        alert(112);
    }
      //如果想传递参数可以在function(a){
	  //  这样传参
      //} 
</script>
<!--子页面--><br><!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <script src="../../commonJS/jquery.js"></script>
    <body>
         
        <a class="btn btn-small btn-info" onclick="addSchduleItem();" title="确定" >确定</a>    
          
    </body>
</html>
<script>
     
    //确定关闭页面
     function addSchduleItem()
    {
         
      if (window.opener != null && !window.opener.closed) {
          window.opener.BBBB();//调用主页面的函数
          //let  a = 1;
          //window.opener.BBBB( a );调用主页面的函数 a是传递的参数。
      }
      window.close(true); 
    }
     
</script>

一句话概括思路:在父窗口中打开子窗口,在子窗口中调用父窗口的方法

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值