Javascript Passing value from a popup window to its parent window

19,765

I finally figured it out Use window.opener

window.opener.document.getElementById('archiveimages').value = address.src;
Share:
19,765
user2044626
Author by

user2044626

Updated on June 11, 2022

Comments

  • user2044626
    user2044626 almost 2 years

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

    Edit:

    This is my javascript code on the popup window

    <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">
    

    Parent Window HTML Code

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

    I Just Can't get it to work

  • user2044626
    user2044626 about 10 years
    Please taka a look on the code in my original post. Thanks
  • user2044626
    user2044626 about 10 years
    I have edited my post and I included a full code that I used. Can you please take a look at it?. Thanks
  • MoustafaAAtta
    MoustafaAAtta about 10 years
    @user2044626 sorry just saw ur edit, glad it's solved.