Try this code: In test.html
function testJS() { var b = document.getElementById('name').value, url = 'http://path_to_your_html_files/next.html?name=' + encodeURIComponent(b); document.location.href = url; }
And in next.html:
window.onload = function () { var url = document.location.href, params = url.split('?')[1].split('&'), data = {}, tmp; for (var i = 0, l = params.length; i < l; i++) { tmp = params[i].split('='); data[tmp[0]] = tmp[1]; } document.getElementById('here').innerHTML = data.name; }
Description: javascript cannot exchange data between different pages, and we must use some solutions, for example. URL get params (in my code that I used this way), cookie, localStorage, etc. Save the name parameter in the URL (? Name = ...) and in the next.html URL and get all the parameters from the previous page.
PS. I am not a native speaker, please correct my message if necessary
Alex Fitiskin
source share