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
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>
本文标签: jqueryHow to access element id from another page using JavaScriptStack Overflow
版权声明:本文标题:jquery - How to access element id from another page using JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744230303a2596298.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论