I open a window through window.open(smth, , , ) , everything is fine; and then I need, by clicking on the link or the transfer button in the main window, the value to the child. But how to access the child window? Already tried many of the methods found on the Internet, and it does not work. Specifically, I need to pass such a value .uppodSend('id','file:rytr.mp3') , referring to the player that is in the child window.

    3 answers 3

    But did you try to use the link to the new window, which the open() method uses as the return result? The new also has a document object, with it you can transfer this value.

    The link will look something like this:

     var newWindow = window.open(bla-bla); newWindow.document.getElemntById('bla').... 

      You need a child window to take the value from the parent, for example:

       var ParentText = window.opener.document.getElementById('parentText').value; 

      And for jquery, you must pass the parent as the second parameter:

       var ParentText = $("parentText", window.opener.document); 

      Or contact the jquery parent window directly:

       var ParentText = window.opener.jQuery("[name=abc]"); 
      • and how the second window will understand that it is time to take this value? - LeD4eG pm
      • For example, by timer, and in the parent window, something will change, which will be polled by the child. - oburejin
      • Correct usecase: opened the child window, did everything you need, in the parent checked what was done interpreted the result. see answer @ LeD4eG - Yura Ivanov

      Recently faced this problem. Only I had an inverse task, it was necessary to open a child window, and it should return a value to the element that opened it. Achieved this in the following way:

      On the parent window:

       <div class="container"> <span class="result"></span> <a href="/listSelect" class="select">Выбрать</a> </div> <script> $(document).ready(function(){ $(".container .select").click(function(){ window.open($(this).attr('href'), 'xxx'); window.onSelect = function(text){ $(this).closest('.container').children('.result').html(text); } return false; }); }); </script> 

      The / listSelect link leads to the contents of the child window. The child window displays:

       <ul class="list"> <li><button data-text="Значение1" value="Вариант1" /></li> <li><button data-text="Значение2" value="Вариант2" /></li> <li><button data-text="Значение3" value="Вариант3" /></li> <li><button data-text="Значение4" value="Вариант4" /></li> </ul> <script> $(document).ready(function(){ $(".list button").click(function(){ var text = $(this).attr('data-text'); if(window.opener.onSelect) window.opener.onSelect(text); return false; }); }); </script> 

      Thus, when creating a child window, I created a function at the parent window, causing that the child window will return the result.

      In your case, you should do something like this:

      Create a player switching function on the child window using incoming arguments, and the parent window should look for the function in the child window at the corresponding event (The child window may not be opened when an action occurs that should cause the player to switch).