I have the html form of the new window and I would like to insert a variable from the main html file c js there, but I can not figure out how to do it. It is necessary that the name that the user entered in the input field appears as text in a new window. Here is my code, please help.

The main function script:

<script> function hello_Programm() { var name = document.getElementById('name').value; var new_window = window.open("form.html", "hello", "width=500,height=500"); return name; } </script> 

HTML main page:

  <body> <center><p class="h1">Welcome!</p></center> <hr> <input class="text_form" type="text" placeholder="Mary Jane" id="name"> <input type="button" value="Hello!" onClick="hello_Programm()"> </body> 

HTML and JS new window

 <body> <center><p><script>//здесь должна быть переменная с именем пользователя</script></p></center> <hr> <p>Take this bouquet as a gift:</p> <img src="rose.png"> </body> 

    1 answer 1

    Try this:

     <script> function hello_Programm() { var name = document.getElementById('name').value; var new_window = window.open("form.html", "hello", "width=500,height=500"); new_window.onload = function() { new_window.document.getElementById('test').innerHTML = name; } return name; } </script> 

    HTML and JS new window:

     <body> <div id="test"> </div> //в этот див вставится Ваше содержимое <hr> <p>Take this bouquet as a gift:</p> <img src="rose.png"> </body> 
    • Alas, it did not work out, but I will look for some other ways) - Mark_8
    • Everything is transferred to me, everything is displayed in chrome and firefox. What actually doesn't work? Are there any errors in the console? - MrFylypenko
    • Does not give any errors, but the line is not even displayed - Mark_8