当前位置: 代码迷 >> 综合 >> window.open打开的页面向父页面传值
  详细解决方案

window.open打开的页面向父页面传值

热度:44   发布时间:2024-01-21 00:17:41.0

父页面:a.html,子页面a_sub.html

a.html

function abc(){

var func = function(){
        var thiswin = window;
        window.fn = function(code){
        $.ajax({
                url:'/xx?code='+code,
                type:'get',
                success:function(msg){
               
                }
                });
        }
        return function(code){
        thiswin.fn(code);
        }
        }
        win.callback = func();
       

}

a_sub.html

<script type="text/javascript">
    $(function(){
    function getUrlParam(name){  
       //构造一个含有目标参数的正则表达式对象  
       var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");  
       //匹配目标参数  
       var r = window.location.search.substr(1).match(reg);  
       //返回参数值  
       if (r!=null) return unescape(r[2]);  
       return null;  
    }
   
    var code = getUrlParam('code');
    callback(code);
    window.close();
        
    });
    </script>

  相关解决方案