admin管理员组文章数量:1405393
First Page
<button onclick="refereceid_Transfer()">Try it</button>
<script>
function refereceid_Transfer() {
alert('test');
var referenceid = "jggd154278";
referenceid = btoa(referenceid);
//sessionStorage.setItem("sent", referenceid);
window.open("second.jsp", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
}
</script>
Second Page
<p id="s1"></p>
<script>
$(document).ready(function(){
// var a = sessionStorage.getItem("sent",id);
alert(a);
});
</script>
I need to pass my reference id from one window to another window. I tried use session storage and local storage to pass variable and i have failed in both condition. is there new suggestion that i can pass my reference id to new window.
Thanks
First Page
<button onclick="refereceid_Transfer()">Try it</button>
<script>
function refereceid_Transfer() {
alert('test');
var referenceid = "jggd154278";
referenceid = btoa(referenceid);
//sessionStorage.setItem("sent", referenceid);
window.open("second.jsp", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
}
</script>
Second Page
<p id="s1"></p>
<script>
$(document).ready(function(){
// var a = sessionStorage.getItem("sent",id);
alert(a);
});
</script>
I need to pass my reference id from one window to another window. I tried use session storage and local storage to pass variable and i have failed in both condition. is there new suggestion that i can pass my reference id to new window.
Thanks
Share Improve this question asked Sep 11, 2017 at 3:29 kuhandran samudra pandiyankuhandran samudra pandiyan 731 gold badge2 silver badges9 bronze badges2 Answers
Reset to default 4You can try localStorage for this.
Add item which you want to pass on another page:
localStorage.setItem("key", "value");
On another page you can access through:
localStorage.getItem("key");
You can store object data as well in localStorage. Note that clear localStorage if you're storing some sensitive information.
And simpler option is to use query parameter, but I think you're not okay with it.
Or you can use sessionStorage:
sessionStorage.setItem("key", data);
window.open("page_url","_blank");
on another page use:
$(document).ready(function(){
var data = sessionStorage.getItem("key");
console.dir(data);
});
Note: The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the specific browser tab.
You can do it with local storage or you can pass it in query parameters and read the query parameters at 2nd page. If you are doing server side rendering you can also use session storage.
本文标签: javascriptHow to pass a variable from current window to another windowStack Overflow
版权声明:本文标题:javascript - How to pass a variable from current window to another window - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744275984a2598414.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论