Skip to content Skip to sidebar Skip to footer

Get Data From One Html File And Display It Using Another Html File

I have 2 html files. I want to take the innerHTML of an element of the 1st HTML file and display it in the 2nd HTML. This is the 1.html file

DATA

<

Solution 1:

Here is code which may help you. In 1.html:

<h1 id="data">Main</h1>
<a href="2.html">
<button onclick="go()">GO</button>
</a>
<script src="action.js"></script>

In 2.html:

<h1 id="display"></h1>
<script src="action.js"></script>
<script>disp();</script>

In action.js:

function go() {
  var data = document.getElementById("data").innerHTML;
  localStorage.setItem("data ", data );
}

function disp() {
  document.getElementById("display").innerHTML = localStorage.getItem("data");
}

Post a Comment for "Get Data From One Html File And Display It Using Another Html File"