Javascript Passing value from popup to parent window

I'm new to javascript and I'm stuck here. Say I have a parent window, and it has an input field, as well as a button that opens a popup. This popup contains images. I just need to copy the image url to this input in the parent window when I click on any image in the popup. Any help please. Thanks

Edit:

This is my javascript popup code

<script type="text/javascript"> function clicked(address) { window.parent.document.getElementById('copy_img').value = address.src; } </script> 

HTML

 <input type="text" name="copy_img" id="copy_img" size="133" /> <img border="0" onclick="clicked(this)" src="images/1.jpg" width="135" height="46"> <img border="0" onclick="clicked(this)" src="images/2.jpg" width="128" height="48"> <img border="0" onclick="clicked(this)" src="images/3.jpg" width="305" height="44"> 

HTML Parent Window Code

 <input type="text" name="copy_img" id="copy_img" /> 

I just can't get it to work

+6
source share
4 answers

I finally figured it out Use window.opener

 window.opener.document.getElementById('archiveimages').value = address.src; 
+7
source

When the user selects an image from the pop-up window, use the following instructions to set the value of the input field. Assuming the input field id is "myInputField"

 window.parent.document.getElementById('myInputField').value = imargeUrl; 
0
source

You can open the window using:

 window.open('http://www.website.com/popup/page?var=test','Note','width=700,height=500,top=150,left=150,scrollbars=yes' 

Then, when you click the popup link, you can do:

 goback('http://www.website.com/page?var=testing'); 
0
source
 window.parent.getImageURL(img.src); 

A popup can access it with JavaScript javascript using the above method, just enter a function (e.g. getImageURL ()) in the global scope and it will work

0
source

All Articles