Nov 20, 2008

Getting value form pervious page into new window

I saw lots of question posted on about how to get the value from pervious page into newly opened window. Its very simple, you have few ways to pass variables to newly opened window. First and foremost is passing variable into query string.

You can get all full form collection; not only this you can also read the value of global variable of parent page in to newly opened window. Let's see how.

I created one variable into parent page. And somewhere I call to open new page into new window.

<script language="javascript" type="text/javascript">
var gblPageTitle;
gblPageTitle = 'Welcome to ';

In parent page I just have to write following line to get that variable.

<script type="text/javascript">
document.title = 'Questions on '+ window.opener.gblPageTitle;

And now lets get the full document of parent page or specifically form collection.

<script type="text/javascript">
var previousForm = window.opener.document.forms;

Have fun with window.opener :)

No comments: