There is such code:

(function aaa(){ var a = window.open("https://site.ru/q/1919", "hello", "width=1500,height=1000"); jQuery(".form--text").val("hello"); }()) 

The idea was to open a window and substitute the value "hello" in the form of textarea.

My window opens, but the value is not substituted in the textarea form.

There are no syntax errors, how to fix it so that it is substituted?

    2 answers 2

    Any bans on security do not allow to roam.
    Must match protocol , hostname and port .
    From https://some.org:1024/how_are_you_dude? You can open any windows, but only https://some.org:1024/all_what_you_want/ will have access to the content ( document , for example).

    The rest will get an error:

    DOMException: Blocked a frame with origin " http://child_window.host " from accessing a cross-origin frame.

    If there is access, it is easy:

     console.info(location.origin); // http://ru.stackoverflow.com let w = window.open("http://ru.stackoverflow.com/q/1919", "hello", "width=1500,height=1000"); w.document.querySelector('.form--text').value = 'hello'; 

    If there is no access, try to solve the problem through frames, iFrame.contentWindow.postMessage and window.addEventListener('message', fn); (in the frame window).
    Well, or pass the parameters to the URI, as suggested by @CostaRaf.

    • Something does not want to substitute, i.e. substitutes for the current window only. Maybe some more focus needs to be done on a new window? - Ilnyr 7:58 pm
    • And what does not work? Show the code. If the security system is pacified, access should be. - user207618
    • For example, from the current page http://ru.stackoverflow.com we want to fill in the header (we will substitute your code): let w = window.open("http://ru.stackoverflow.com/questions/ask", "hello", "width=1500,height=1000"); w.document.querySelector('input#title').value = 'hello'; let w = window.open("http://ru.stackoverflow.com/questions/ask", "hello", "width=1500,height=1000"); w.document.querySelector('input#title').value = 'hello'; The window opens, but does not substitute the value + gives an error: Uncaught TypeError: Cannot set property 'value' of null(…) Is this due to access or because of syntax? How can I solve the error above? - Ilnyr pm
    • 1) #title . 2) Everything works, the error indicates that the item was not found. Why - I don’t know exactly how you ran, because it works for me (chrome, fox). Show all your code. - user207618 pm
    • From the current page (on which we are discussing now) I substituted the code that I specified above ( let w = window.open("http://ru.stackoverflow.com/questions/ask", "hello", "width=1500,height=1000"); w.document.querySelector('input#title').value = 'hello'; ) through the chrome developer tool (I also tried it through the fox) and that's it, this is all the code - Ilnyr

    There is not a lot of choice ... Try to pass the value to textarea through the url parameter

     var a = window.open("https://site.ru/q/1919?param=hello", "hello", "width=1500,height=1000"); 

    and intercept it on the side of the opening window:

     var sPageURL = decodeURIComponent(window.location.search.substring(7)) $(".test1").html(sPageURL);