Access parent window from <object>

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Access parent window from <object>

Post by pickle »

Hi everyone,

I'm having a heck of a time in IE8 trying to access a javascript variable in a parent window of an <object>.

In XHTML, the <iframe> tag isn't allowed, so the <object> tag is supposed to be used in it's place like this:

Code: Select all

<object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data = "/path/to/upload.html" type = "text/html" class = "upload-ie"></object>
However, in upload.html, I can't access any variables I have defined in the parent window - either using window.parent.myDefinedVariable, or window.myDefinedVariable.

If I use an <iframe> instead of an <object>, it works just fine with window.parent.myDefinedVariable, but with the <object>, it always says undefined. I can access window.parent, because when I iterate through all the properties, some stuff does come up (standard javascript properties as well as the jQuery object), just nothing I've defined.

Anyone know what I have to do in IE to be able to access custom defined variables?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: Access parent window from <object>

Post by ell0bo »

"The <object> tag is used to include objects such as images, audio, videos, Java applets, ActiveX, PDF, and Flash"

I'm pretty sure what you're trying to do isn't really legal, and I'm not certain iframe isn't allowed in XHTML...
http://webdesign.about.com/od/htmltags/ ... iframe.htm

Either way, the reason it's not working is because objects aren't registered the same way iframes are.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Access parent window from <object>

Post by Weirdan »

ell0bo wrote:"The <object> tag is used to include objects such as images, audio, videos, Java applets, ActiveX, PDF, and Flash"
And how html is really different from flash or image? It's just another external entity.
I'm pretty sure what you're trying to do isn't really legal
Care to justify?
, and I'm not certain iframe isn't allowed in XHTML...
It isn't allowed in XHTML strict.
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: Access parent window from <object>

Post by ell0bo »

See... I need to not respond to stuff when hungry. Actually your code does look like it should be working. I'm honestly just not a fan of using object in this manor, or at least in a complex manor. Personal bias I'm prolly going to have to get over. It's mainly because, now maybe I've missed something here, but putting classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" in the object chokes Firefox, but without it IE won't load the frame.

ANYWAY... I do recall IE8 being a little odd with how it loads things and what order it will run stuff.

Take for instance these two scripts:

index.htm

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 

<html>
<head>
</head>
<body>

<iframe src="help.htm"></iframe>
<!--
<object     classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13"
		data = "help.htm"  
		type = "text/html"  class = "upload-ie">
<p>well that doesn't work at all</p>
</object>
-->
<script>
var woot = 5;
alert( window.frames.length );
alert( window.parent.woot );
var f = window.frames[0];
alert( f.woot );
</script>
</body>
</html>
help.html

Code: Select all

<html>
<head></head>
<body>
<script>
var woot = 2;
alert( '----' );
alert( window.parent.woot );
</script>
hello work
</body>
</html>
Yes, I'm kinda implementing a race condition here, but this is just trying to show a point. Run it in IE6, Firefox, and IE8. Notice something odd?

Yup, IE6 and IE8 load it in completely different orders. So different in fact that IE8 won't be able to display the data from the iframe. So, perhaps your problem is the order you're allowing things to get loaded? Remember, the browsers will try to load two things simultaneously, not just one at a time. IE6 actually seems to load it in the move correct order.

Now, if I switch if over the <object> the JS doesn't even run in either of the IE instances. This could however be a result of the security settings here, I will need to test this at home.

Hope this at least gives you an idea of a way to go. However, from what I remember, what you're trying to do just won't work with <object> and IE.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Access parent window from <object>

Post by pickle »

I posted this on StackOverflow & the feedback I got was to say to heck with <object> and XHTML 1.1 String, and revert to XHTML 1.0 Transitional and use an iframe. I've just tried that & it works fine in both Firefox & IE8, so I'm going to go with that. It feels a bit like giving up, but I don't have countless hours & patience to fart around with it.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Access parent window from <object>

Post by AbraCadaver »

pickle wrote:I posted this on StackOverflow & the feedback I got was to say to heck with <object> and XHTML 1.1 String, and revert to XHTML 1.0 Transitional and use an iframe. I've just tried that & it works fine in both Firefox & IE8, so I'm going to go with that. It feels a bit like giving up, but I don't have countless hours & patience to fart around with it.
Yes, the other axe-wielding psychopaths that know where you live and I, don't like farting around with your object tags!
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Access parent window from <object>

Post by pickle »

Ya, exactly. Always have to be mindful of the axe-wielding maniacs.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Access parent window from <object>

Post by Christopher »

pickle wrote:I posted this on StackOverflow & the feedback I got was to say to heck with <object> and XHTML 1.1 String, and revert to XHTML 1.0 Transitional and use an iframe. I've just tried that & it works fine in both Firefox & IE8, so I'm going to go with that. It feels a bit like giving up, but I don't have countless hours & patience to fart around with it.
Sounds like the way to go. I get the impression that XHTML is a dead-end anyway. It would probably be better to move to HTML5.
(#10850)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Access parent window from <object>

Post by pickle »

HTML5 is still a working draft. I'm hesitant to use an emerging standard in a mission critical app. Maybe once IE9 comes out.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply