0

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.

A H
  • 235
  • 2
  • 5
  • 15
  • ... why aren't you either sending the data to the second page via the server OR loading the second page async so that you don't refresh the entire document? – Evan Davis Jan 03 '13 at 21:40
  • This is a mobile site and I'm trying to limit the calls to the server. I get the data from the server on the first page and its huge. – A H Jan 03 '13 at 21:42
  • Are you trying to build a single-page webapp? – Evan Davis Jan 03 '13 at 21:45
  • Theres three pages that all need to share the same json string. – A H Jan 03 '13 at 21:46

1 Answers1

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.
Cyril N.
  • 38,875
  • 36
  • 142
  • 243