PDA

View Full Version : Sending data to another window with layers


jonathan
10-18-2002, 10:50 PM
What I'm trying to do is send data from one window to another. I'm useing the window.opener method and it works fine in IE6. (ex. "window.opener.divlayer.document.formname.elementname.value") My problem, I think, is that the field I want to send it to is inside a layer(div). NS6.2 doesn't seem to work with it. Any way of going around this issue, like being able to search a specific field in another window.

adios
10-19-2002, 01:55 AM
Problems here:

1) No such thing as a 'layer' (NS4 excepted). A <div> is just another HTMLElement; positioning it relatively/absolutely just applies some CSS attributes to it - it's still just an element. If you want to call it a 'layer', well, OK, but it's still an element - no special referencing required for any other elements nested within it, unless you're using newer DOM (element tree) referencing.

2)window.opener isn't a 'method' - it's just a property (opener is sufficient): in other words, a variable name.

Without more info, hard to say more. Your problem probably lies elsewhere.

This works in IE?

opener.divlayer.document.formname.elementname.value

Hmm...I think every HTMLElement may have a document property, pointing to the containing document. Going 'up' to go 'down' again, so to speak.


OK, just confirmed that...

<html>
<head>
<title>Hello</title>
</head>
<body>
<div id="test"></div>
<script type="text/javascript" language="javascript">
var d = document.getElementById('test').document;
d.write(d.title);
</script>
</body>
</html>

jonathan
10-21-2002, 06:43 PM
Well I played around with it some more but no luck. I've include some sample files that pretty much do the same as the ones I'm working on. On the main page I don't really have anything special just a function to open the popup page.
On the popup I have this written in the javascript.
<script type="text/JavaScript" language="JavaScript1.2">
<!--
function sendinfoback()
{
var layername = "layer1";
var fieldname = "field1";
var datafieldvalue = document.popupform.textfield.value;

//window.opener.layer1.document.layer1form.field1.value = datafieldvalue;
eval("window.opener."+layername+".document."+layername+"form."+fieldname+".value = \""+datafieldvalue+"\"");
}

-->
</script>
I also tried to the hardcoded way commented out above but it had the same remarks in Netscape 6.2

The error I get is "Error: window.opener.layer1 has no properties
Source File: file:///A:/Javascripttest/popup.html
Line: 16"

glenngv
10-22-2002, 03:25 AM
window.opener.document.formname.elementname.value

i think that is just fine even if the element is inside a div.

jonathan
10-26-2002, 03:23 AM
Well I finally got it to work, and yes there must have been something wrong with my code. Though I have to admit that I had some help from Dreamweaver with their findObj() function. All I did was put opener in front of that. It makes sense now that I look back on it. I suppose the getElementByID would work too, haven't tried it though. Something like this: opener.getElementByID("object id"); It's so much easier this way especially if you have elements nested within other elements.