Post #6,463
8/23/01 12:28:19 PM
|
Nope.
That just gives the parent DOM element. I need the Frame or Window, which isn't represented in the DOM other than as the owning Document. I need a Javascript-specific method on it though, and the DOM object doesn't have it.
What I'm trying to do is call a script in the owning window of a particular DOM element. The calling script is in the root context, so it doesn't know anything in the Frame scope. Window has execScript() on it, but I can't get the Window object given the HTMLElement object.
Regards,
-scott anderson
|
Post #6,503
8/23/01 2:50:37 PM
|
Either call from the element itself or pass params
Ideas:
1) How does the root script know which element it is? Pass the window object in the same argument list.
2) Use the trappable events system to call the (for example) onClick event of the element.
3) Otherwise, you have to make the call from the element itself.
Wanna post pseudocode? I work in client-side JS a lot (with frames), you can email me if you want: ts under_score eliot at pacbell.net
That's her, officer! That's the woman that programmed me for evil!
|
Post #6,520
8/23/01 3:48:22 PM
|
I passed params.
I'm traversing the entire window, and picking out elements with certain attributes. I fixed my problem by passing the beginning window into the (recursive) traversal function, and setting it on the element placeholder when I get one I want to keep.
Regards,
-scott anderson
|
Post #6,504
8/23/01 2:51:58 PM
|
My stuff's not in front of me...
...I vaguely recall having been down that road before. It's possible to get the enclosing window. What is regulated though, is the ability of one frame to call a function in another frame - some security issues get involved.
Anyhow, if you haven't found it by then, I'll try to look it up.
|
Post #6,521
8/23/01 3:49:36 PM
|
We own all of the frames.
So security shouldn't be an issue.
If you can find your code that gets the enclosing window and let me know, I'd appreciate it. The method I'm using now (passing the window as a parm) works, but it's a bit inelegant.
Regards,
-scott anderson
|
Post #6,539
8/23/01 6:35:02 PM
|
hmmm...
Found some really old stuff for Navigator 3, but it just set up a frame level property that was stored as the page was being created. Don't know if this is what you are aiming at, but here's a stab: main.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "[link|http://www.w3.org/TR/html4/frameset.dtd|http://www.w3.org/T...frameset.dtd]"> <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' /> <title>Main</title> <script language='JavaScript' type='text/javascript'> function justForGrins(myparam) { alert(myparam); } </script> </head> <frameset border="3" rows="50%,*"> <frame src="framea.html" name="bodya" frameborder="1" marginheight="80" marginwidth="120" /> <frame src="frameb.html" name="bodyb" frameborder="1" marginheight="80" marginwidth="120" /> </frameset> </html> framea.html<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' /> <title>Frame A</title> <script language='JavaScript' type='text/javascript'> function tryThis(obj) { obj.document.frames.parent.justForGrins("fred was here"); alert(obj.document.frames.parent.window); } </script> </head> <body> Frame A Contents <form name='myform' action='framea.html'> <input name='fred' type='button' value='say' onclick='tryThis(this);' /> </form> </body> </html> frameb.html<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' /> <title>Frame B</title> </head> <body> Frame B Contents </body> </html>
|
Post #6,583
8/24/01 9:02:43 AM
|
No dice.
Apparently when you walk the DOM to get to an object, it's not the same object as the one referred to by "this".
I just get "node.document has no properties".
Regards,
-scott anderson
|
Post #6,602
8/24/01 11:52:28 AM
|
Non standard
Not sure if there is a standard way to get there, but here's a non-standard technique that works with ie & ns differences built into the code. The dump routine just dumps all the properties and methods so I could try to track my way throw the collections (thought it might be useful). <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' /> <title>Frame A</title> <script language='JavaScript' type='text/javascript'> function tryThis(node) { if (node.document) { node.document.frames.parent.justForGrins("Internet Exploder"); alert(node.document.frames.parent.window); } else if (node.ownerDocument) { node.ownerDocument.defaultView.parent.justForGrins("NetScrape"); alert(node.ownerDocument.defaultView.parent.window); } else { alert("SOL"); } }
function dump(myObj) { if (myObj == null) { document.write("null<br>"); } else { document.write("<table border=\\"3\\">"); document.write("<tr><th>Property</th><th>Value</th><th>Type</th></tr>"); for (var i in myObj) { document.write("<tr>"); document.write("<td width=\\"200\\">" + i); document.write("<td width=\\"200\\">"); if (myObj[i] != null) { if (typeof(myObj[i]) == "string") { document.write("\\"" + myObj[i] + "\\""); } else { document.write(myObj[i]); } } else { document.write("null"); } document.write("<td width=\\"100\\">" + typeof(myObj[i])); } document.write("</table>"); } document.write("<br>"); } </script> </head> <body> Frame A Contents <form name='myform' action='framea.html'> <input name='fred' type='button' value='say' onclick='tryThis(this);' /> </form> <script language='JavaScript' type='text/javascript'> var node = document.getElementsByName("fred").item(0); dump(node);
if (node.document) { dump(node.document.frames.parent); } else { dump(node.ownerDocument.defaultView.parent); } </script> </body> </html>
|
Post #6,611
8/24/01 12:43:26 PM
|
Yes, that seems to work.
But since I've already written by passing the Window object along during traversal, and this would be the first browser-specific code I'd have had to add, I think I'll stick with what I've got.
Thanks.
Regards,
-scott anderson
|
Post #6,633
8/24/01 3:00:55 PM
|
Natch
Figured as much, but just wanted to complete the thought. :-)
Looks like the defaultView property may become a w3c standard sometime down the road. One thing that stuck out, though, is that I couldn't find the ownerDocument property in IE5.5 and that is part of the core DOM standard. And Opera JavaScript still seems to be lagging.
I gather y'all are standardizing on the latest builds of Mozilla. Out of curiosity, what IE version are they using? I still have some apps that have to go back to navigator 2.x and ie 3.x, though I'm not sure anybody is still out there using them.
|
Post #6,677
8/25/01 3:34:12 PM
|
Still some problems with DOM in IE 5.5
NOt nearly as bad as the incompatibility problems of the past, but still annoying.
IE treats element attributes completely differently than Mozilla. Mozilla uses the W3C method of treating attributes as child nodes of the element; IE treats the attributes as a mapping on the element.
Regards,
-scott anderson
|
Post #6,540
8/23/01 6:51:50 PM
|
"All your frame are belong to us"?
sorry...haven't had my fix in a few weeks. Needed a quick hit of AYBABTU
Jay O'Connor
"Going places unmapped to do things unplanned to people unsuspecting"
|