How do I pass any array to a window being opened with window.open()

吃可爱长大的小学妹 提交于 2020-01-22 03:06:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!