javascript - How to pass a variable from current window to another window -
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 = sessionstorage.getitem("sent",id); alert(a); }); </script>
i need pass reference id 1 window window. tried use session storage , local storage pass variable , have failed in both condition. there new suggestion can pass reference id new window.
thanks
you can try localstorage this.
add item want pass on page:
localstorage.setitem("key", "value");
on page can access through:
localstorage.getitem("key");
you can store object data in localstorage. note clear localstorage if you're storing sensitive information.
and simpler option use query parameter, think you're not okay it.
or can use sessionstorage:
sessionstorage.setitem("key", data); window.open("page_url","_blank");
on page use:
$(document).ready(function(){ var data = sessionstorage.getitem("key"); console.dir(data); });
note: the sessionstorage object equal localstorage object, except stores data 1 session. data deleted when user closes specific browser tab.
Comments
Post a Comment