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.

4
  • ... 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? Commented Jan 3, 2013 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. Commented Jan 3, 2013 at 21:42
  • Are you trying to build a single-page webapp? Commented Jan 3, 2013 at 21:45
  • Theres three pages that all need to share the same json string. Commented Jan 3, 2013 at 21:46

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.