Link to home
Start Free TrialLog in
Avatar of jonatec
jonatecFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

SOLUTION
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonatec

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonatec

ASKER

Thanks.