javascript - Passing Variable from child popup window to parent popup window -


i have popup window goes upload.jsp, upload file directory.

the uploading logic written in upload.jsp. problem wanted saved path parent popup window textfield.

the child window has property, opener, refers window opened it. provided they're both same origin, child can access global variables on parent this:

opener.globalvariable 

that means can access parent window's document opener.document, , can use opener.document.getelementbyid or opener.document.queryselector @ elements in parent window.

example:

parent page:

<!doctype html> <html lang="en"> <body> <input type="text"><input type="button" value="click me"> <script> document.queryselector("input[type=text]").value = math.floor(math.random() * 10000); document.queryselector("input[type=button]").addeventlistener(   "click",   function() {     var wnd = window.open("popup.html");   },   false ); </script> </body> </html> 

popup page:

<!doctype html> <html> <body> <script> var field; if (!opener) {     display("not opened popup"); } else {     field = opener.document.queryselector("input[type=text]");     display("value " + field.value); }  function display(msg) {     var p = document.createelement('p');     p.innerhtml = msg;     document.body.appendchild(p); } </script> </body> </html> 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -