问题
I have any array called query[]
I am opening a new window with:
window.open("http://localhost:8081/myapp/Query.action","mywindow","menubar=1,resizable=1,width=600,height=400");
How do I pass this array to the new window so I can use it there.
EDIT: I just found this, Pass array to Window which will probably provide the answer.
EDIT2: the answer provided in question 2487420 doesn't seem to work, I am using FireFox and openDialog never opens a new window
New Requirement: This only has to work on FireFox because I am only using it for testing.
回答1:
You can't "pass" the array, but you can make it available as a global (or via a global), and your new page can use something like:
var theArray = window.opener.theArray;
to get access to it.
Alternatively, you could pass the array through as a list of parameters, but if it's not otherwise interesting to the server then that would be a little wasteful.
回答2:
You can also pass it on the URL as well, for example:
window.open("http://localhost:8081/myapp/Query.action?arr=" + query.join(","), "mywindow", ...
This will pass it as comma separated list that can be read in the target page.
来源:https://stackoverflow.com/questions/5848333/how-do-i-pass-any-array-to-a-window-being-opened-with-window-open