passing a variable with window.opener javascript

2019-08-30 07:50发布

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条回答
手持菜刀,她持情操
2楼-- · 2019-08-30 08:19

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.
查看更多
登录 后发表回答