window.opener不起作用 [英] window.opener is not working

查看:668
本文介绍了window.opener不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在打开一个网页,通过点击父窗口上的图像打开一个弹出的子窗口。



我想将值将子窗口的文本框添加到父窗口的文本框中。



我找到了关于此主题的教程并遵循了他的方法。
http://www.plus2net.com/javascript_tutorial/window-child3 -demo.php
然而,它并没有为我工作。

  $(document).ready(function(){
$(#myImg)。click(function (){
var win1 = window.open(popupWindows / p1.html,myWindow,top = 500,left = 500,width = 500,height = 500);
} );
});

^打开子窗口。



< pre $ function childWindowFunction()
{
opener.document.getElementById(parentTextBox)。value = document.getElementById(userInput)。value;
//alert(document.getElementById(\"userInput\").value); < - 这工程
//alert (opener.document.getElementById(\"parentTextBox\").value); < - 根本不工作
close();
}

^从子窗口执行。



这里是可执行代码。
https://www.dropbox.com/s/83hwyhbz7u4nuie/sandbox.7z



我猜测 opener.document.getElementById(parentTextBox).value 不起作用。有人能告诉我什么是错的吗?谢谢!






忽略上面的代码。我为此创建了一个jsfiddle。 jsfiddle.net/yuyhero/6FKVM/1



我想使用弹出窗口中的按钮来完成任务,而不是使用父窗口中的get value按钮。



现在弹出窗口中的按钮根本不起作用。



感谢您的帮助! / p>

解决方案

想象一下,您使用window.open创建myWindow,然后从myWindow中使用窗口。打开创建windowTheSequel。



您现在有两个开启者,例如原始的浏览器窗口和myWindow。因此,如果没有儿童(myWindow)作为参考,opener不知道要引用哪个窗口。



因此,从 myWindow.opener ... 开始行,你应该很好。


I'm working on a webpage that opens up a popup child window by clicking an image on the parent window.

And I would like to pass the value from the child window's text box to the parent window's text box.

I have found a tutorial on this topic and followed his method. http://www.plus2net.com/javascript_tutorial/window-child3-demo.php However it didn't work for me.

$(document).ready(function(){
  $("#myImg").click(function(){   
    var win1=window.open("popupWindows/p1.html","myWindow"," top=500, left=500, width=500,height=500");
    });
});

^ This opens up the child window.

function childWindowFunction()
{
opener.document.getElementById("parentTextBox").value=document.getElementById("userInput").value;
//alert(document.getElementById("userInput").value); <-- this works
//alert(opener.document.getElementById("parentTextBox").value); <-- not working at all
close();
}

^ This executes from the child window.

And here is the executable code. https://www.dropbox.com/s/83hwyhbz7u4nuie/sandbox.7z

I guess the opener.document.getElementById("parentTextBox").value is not working. Can someone tell me what's wrong? Thank you!


Ignore the code above. I have created a jsfiddle for this. jsfiddle.net/yuyhero/6FKVM/1

I would like to use button inside the popup window to do the task instead of using the get value button from the parent window.

Now that the button inside the popup window does not work at all.

Thanks for your help!

解决方案

Imagine for a moment that you use window.open to create "myWindow" and then from within "myWindow" you use window.open to create "windowTheSequel".

You now have two "openers", e.g. the original browser window and "myWindow". Therefore, opener wouldn't know which window to reference without the child (myWindow) as a reference.

So begin the line with myWindow.opener... and you should be good to go.

这篇关于window.opener不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆