passing a variable with window.opener javascript

故事扮演 提交于 2019-12-13 04:51:44

问题


In the first page I have

window.tmpstr = 'aaaaaa';
window.open ('second.php','_self',false);

in second.php

alert(window.opener.tmpstr)

This alerts 'undefined'. when I change '_self' to '_blank' it works. How can I pass the variable when I want the new window to open in the same window.


回答1:


You can't, not like that. By calling window.open using _self, you simply redirect the page to the second.php url.

Options you can use are :

  • Adding it as a parameter using the hash tag (second.php#tmpstr=aaaaaa
  • Using cookies (there is a nice jQuery cookie plugin)
  • Moving your whole page into a iFrame (not recommended) and redirecting only the main frame.


来源:https://stackoverflow.com/questions/14147680/passing-a-variable-with-window-opener-javascript

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