Page 1 of 1
Access parent window from <object>
Posted: Tue May 11, 2010 3:54 pm
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?
Re: Access parent window from <object>
Posted: Thu May 13, 2010 1:24 pm
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.
Re: Access parent window from <object>
Posted: Thu May 13, 2010 1:35 pm
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.
Re: Access parent window from <object>
Posted: Thu May 13, 2010 2:50 pm
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.
Re: Access parent window from <object>
Posted: Thu May 13, 2010 3:05 pm
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.
Re: Access parent window from <object>
Posted: Thu May 13, 2010 3:56 pm
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!
Re: Access parent window from <object>
Posted: Thu May 13, 2010 4:31 pm
by pickle
Ya, exactly. Always have to be mindful of the axe-wielding maniacs.
Re: Access parent window from <object>
Posted: Thu May 13, 2010 4:38 pm
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.
Re: Access parent window from <object>
Posted: Thu May 13, 2010 5:06 pm
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.