Passing parameters from parent to child window using JS

Hi.

I am using IE9 and want to use JavaScript to pass parameters from a parent html page to a second child page.

I am calling from the parent using window.open('childPage.htm') and getting the parent fiels values using window.opener.document.getElementById('xxx').value in the child. This works fine.

However I have to open the child in the same window, so when I change the calling code to window.open('childPage.htm','_self') I get an error at the child:

"Microsoft JScript runtime error: Unable to get value of the property 'document': object is null or undefined"

Any ideas please?
<html>
<head>
<title></title>
<script type="text/javascript">
	function fnGo() {
		window.open('childPage.htm','_self');
	}
</script>
</head>
<body>
<h3>PARENT</h3><p />
First Name:&nbsp;<input id='txtFirstName'  name='txtFirstName' value='Fred'/><br />
Last Name:&nbsp;<input id='txtLastName'  name='txtLastName' value='Smith'/><p />
<input type="button" value=" pass params " onclick="fnGo()" />
</body>
</html>



<html>
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
	$('document').ready(function () {

		var FirstName = window.opener.document.getElementById('txtFirstName').value;
		var LastName = window.opener.document.getElementById('txtLastName').value;

		$('#labFirstName').text(FirstName);
		$('#labLastName').text(LastName);

	});
</script>
</head>
<body>
<h3>CHILD</h3>
First Name:&nbsp;<label id='labFirstName'></label><br />
Last Name:&nbsp;<label id='labLastName'></label>
</body>
</html>

Open in new window

jonatecAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee SavidgeCommented:
If you open to _self the parent is no longer tehere so you will get this error. When opening, just send the parameters on the query string.

window.open('childPage.htm?p1=val1&p2=val2','_self');

Then in the child page just query the query string.

0
jonatecAuthor Commented:
Thanks, not allowed to use a querystring re security. The whole system runs as a dot net web app, maybe I'd be better off storing the parameters in a session variable I was just trying to avoid this by using JS.
0
Lee SavidgeCommented:
If it's a .net web app then the session would be ok to use. Failing that, a page post as normal so the data is in the http header but I guess there is a reason why you're not doing that.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jonatecAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.