How to connect two pages between each other?

For example, there is a login page where the user name is requested, and a second page where the name entered at the entrance is used (display, output, etc.). Example, when you click on the add-name, the entered value is remembered and, in theory, there should be a transition to the next page, how can this be correctly implemented? And will not there be conflicts from two pages using the same code (file, the variables will be simple others)?

$(document).ready(function() { var name = ""; $("#add-name").click(function() { name = $("#name").val(); if($("#name").val() == "") { alert("Введите имя"); return false; } return false; }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form" action="#" method="POST"> <input id="name" type="text" placeholder="Введите имя"> <input id="add-name" type="submit" value="Продолжить"> </form> 

    1 answer 1

    Greetings If without using PHP, there are not many options.

    1. JavaScript only works on a specific page and has no idea what is happening on neighboring ones. <a href="next-page.html?name=вася">click</a> parameter via the URL: <a href="next-page.html?name=вася">click</a> And on next-page.html, parse location.href . Replace only method in the form with GET , instead of POST .
    2. Use any plugin to work with cookies , like a js-cookie, after submitting the form, save the data there and retrieve it on the page you need. But cookie sizes are very limited. As in principle, and the body of the GET request for option 1, so do not particularly get carried away. :)
    3. Good old PHP .
    • And if the name is saved in localstorage? and how then input indicate the link? for example, the input data is first checked, after the data is stored in localstorage, and then the link is followed. How can this be implemented? - John-n
    • It is possible in localStorage, or sessionStorage, with the only difference that the session is cleared after closing the tab, like any session. On localStorage there is just a great article: "LocalStorage on the fingers . " Check out if something is not clear, ask! ;) - Stanislav Hmelevsky