【问题标题】:Pass data back to parent using javascript使用 javascript 将数据传回给父级
【发布时间】:2015-04-21 10:24:53
【问题描述】:

我使用window.open 使用google 登录下面是我的代码。

$('window').ready(function() {
    $('#googlebtn').click(function() {
        mywindow = window.open("'<?php echo base_url();?>'+authenticate/google","Auth","height=470,width=430")

        window.setInterval(function(){            
            if(mywindow.closed == true){
                window.location.href = '<?php echo base_url();?>'+'checklogin/email';                
            }
        },3000);
    });   
});

但我想要的是验证关闭后打开的新窗口中的数据。 我已经尝试在我的新窗口中向父级声明变量

window.opener.varFromParent = '1';
window.close();

然后尝试在计时器内向我的父母验证我的变量

if(varFromParent == '1'){alert(1);}

我不能让它工作。

【问题讨论】:

  • 控制台中有错误信息吗?
  • @Katrin 我父母的控制台?因为一旦用户使用 google.i 进行身份验证,就会使用 window.close()
  • 那么你现在的结果是什么?没有显示 varFromParent 值已更改的警报框?
  • 顺便说一句,你没有引用变量 mywindow,var mywindow = window.open("''+authenticate/google","Auth", "高度=470,宽度=430")
  • @Katrin 对此感到抱歉。我只是打错了代码。是的,我的变量没有改变

标签: javascript php jquery codeigniter


【解决方案1】:

如果您可以使用带有隐藏字段的表单。

parent.html
<form name="myForm">
<input type="hidden" name="hdn" />
</form>

child.html
<script>
window.opener.document.myForm.hdn.value="Any value";
</script>

【讨论】:

    【解决方案2】:

    应该是

    window.parent.varFromParent = '1';
    

    而不是开瓶器。

    window.parent 只是返回父窗口的窗口对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 2020-09-22
      • 1970-01-01
      • 2011-09-07
      • 2017-03-23
      • 2018-07-31
      相关资源
      最近更新 更多