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
2 Answers
Reset to default 3you 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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744230303a4564214.html
评论列表(0条)