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

前端 未结 2 986
终归单人心
终归单人心 2021-01-28 22:54

I have any array called query[]

I am opening a new window with:

  window.open(\"http://localhost:8081/myapp/Query.action\",\"mywindow\",\"me         


        
相关标签:
2条回答
  • 2021-01-28 23:23

    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.

    0 讨论(0)
  • 2021-01-28 23:31

    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.

    0 讨论(0)
提交回复
热议问题