Results 1 to 2 of 2

Thread: Javascript Passing value from a popup window to its parent window

  1. #1
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript Passing value from a popup window to its parent window

    down vote favorite


    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.

    This is my javascript code on the popup window

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

    Code:
    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

    Code:
    <input type="text" name="copy_img" id="copy_img" />
    I Just Can't get it to work!. Any help please. Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Looks workable except a parent contains a frame. If you are popping up a window, it's "parent" (more accurately the window that generated it) is it's opener:

    Code:
    <script type="text/javascript">
    function clicked(address) {
        window.opener.document.getElementById('copy_img').value = address.src;
    
    }
    </script>
    And, for cross window scripting you need to observe the same origin policy. This means that both the opener and the popup have to be on the same domain.

    There could also be other problems.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Refresh Parent window on close of Popup window
    By samijsr in forum Dynamic Drive scripts help
    Replies: 7
    Last Post: 09-05-2011, 05:21 AM
  2. creating form in the parent window from popup
    By ankurpremi in forum JavaScript
    Replies: 0
    Last Post: 08-09-2010, 05:49 PM
  3. passing data from parent window to popup
    By meenakshi in forum JavaScript
    Replies: 14
    Last Post: 07-10-2008, 06:14 PM
  4. Replies: 1
    Last Post: 05-31-2008, 03:38 PM
  5. Onclick popup AND parent window close?
    By typhoidtimmy in forum JavaScript
    Replies: 1
    Last Post: 02-29-2008, 07:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •