admin管理员组

文章数量:1401314

I am trying to access an element id of an HTML page from another page. I have seen other solutions but none have worked so far.

For example, if this is One.html

<input id="a" type="text"></input>
<p id="demo"></p>

I am trying to access the element id 'a' from Two.html to get the value that has been inputted using `

var thing = document.getElementById('a').value;
document.getElementById('demo').innerHTML = "the value is" + " " + thing;

I am trying to access an element id of an HTML page from another page. I have seen other solutions but none have worked so far.

For example, if this is One.html

<input id="a" type="text"></input>
<p id="demo"></p>

I am trying to access the element id 'a' from Two.html to get the value that has been inputted using `

var thing = document.getElementById('a').value;
document.getElementById('demo').innerHTML = "the value is" + " " + thing;
Share Improve this question asked Dec 3, 2016 at 5:55 Sandeep RaoSandeep Rao 111 gold badge1 silver badge6 bronze badges 3
  • not from your current web page? – Luminous_Dev Commented Dec 3, 2016 at 5:57
  • only under very limited conditions can pages talk to each other so we need more details before we can help you – Bindrid Commented Dec 3, 2016 at 5:58
  • Is two.html ever loaded into your browser? – Rajshekar Reddy Commented Dec 3, 2016 at 6:10
Add a ment  | 

2 Answers 2

Reset to default 3
you can use localStorage 
for example in firstpage.html you save data with
var thing = document.getElementById('a').value;
localStorage.something = thing ; 
then in your seconpage.html you can use it by
document.getElementById("demo").innerHTML=localStorage.something;

sorry I don't have enough reputation to leave this as a ment but just a heads up, input tags are standalone tags.

Example: 
  <body>
    <input type="text" id="a" />
  </body>

本文标签: jqueryHow to access element id from another page using JavaScriptStack Overflow