我正在使用 window.open 登录,下面是我的代码。
$('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);}
我无法让它工作。
最佳答案
如果你可以使用带有隐藏字段的表单。
parent.html
<form name="myForm">
<input type="hidden" name="hdn" />
</form>
child.html
<script>
window.opener.document.myForm.hdn.value="Any value";
</script>
关于javascript - 使用javascript将数据传回父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29769515/