View Full Version : Accessing the contents of an html/text typed object
kgiguere
06-16-2009, 07:22 PM
I have an object, which data points to an HTML page. I want to send information from child to parent, through javascript. Is it possible? If not, what are my options to resolve this issue?
Gjslick
06-17-2009, 12:20 AM
Some questions:
1) What is this mysterious "html/text typed object?" Is it a JavaScript object? Is it a string? Is it a reference to a web page?
2) What do you mean "which data points to an HTML page?" Do you mean you have a variable that references a loaded web page? (like 'window', or 'top' ?)
3) What is the child and what is the parent? Windows? Frames? JS Objects?
kgiguere
06-17-2009, 04:08 PM
An text/html typed object is this:
<object id="objPage" data="player.html" type="text/html"></object>
I'm not sure if there's a better name for it.
I think this answers all three questions, the object embeds another HTML page in the current one.
Gjslick
06-17-2009, 08:04 PM
Ahh, I see. In all my 12+ years of doing this stuff, I have never used an object tag to embed an html document, nor have I even seen that done.. When you said you had an "object," and this being the JavaScript Forum, I assumed you had a JavaScript object and/or reference, lol.
That being said, are you sure you want to be embedding an html file with the object tag? It might be better to use an iframe instead.
But, to access the parent document through script from your embedded file (player.html), you reference it by using window.parent (just like you would with an iframe, in case you are considering switching).
Here's an example. Say your parent document had a function named sayHi. You would call that function from player.html with:
<script>
window.parent.sayHi();
</script>
Hope that helps!
rnd me
06-17-2009, 09:08 PM
iframes don't work in XHTML, only objects.
no, there is not a standard mapping to <object> contents, that's why they replaced iframes...
Gjslick
06-17-2009, 09:34 PM
Snap, I didn't realize iframes weren't supported by the w3c purists creating the strict xhtml spec. Inline frames are a widely used device in web applications (read exactly as "web applications", not "web pages"), and for them to take them out (in my opinion) is just plain stupidity. The object tag is in no way, shape, or form, a valid replacement for iframes. But anyway, iframes are still available in the transitional xhtml specification.
As of now though, it seems that html documents embedded with the object tag still do get a reference to their parent document through window.parent.
kgiguere
06-18-2009, 02:21 PM
I couldn't get it to work with window.parent, but I came across jQuery and decided to use that for my needs. Thank you for your help.
Gjslick
06-18-2009, 05:15 PM
jQuery is a great library, but I still don't see how that helps you access your parent document from your child document...
kgiguere
06-18-2009, 05:21 PM
It doesn't, but I just sent and treated the information elsewhere, which worked for the purpose I needed it.
Gjslick
06-18-2009, 06:59 PM
Ah, gotcha. Well, I'm glad you figured out what you needed to figure out then :)
All the best
chichilatte
04-30-2010, 12:50 AM
Hi kgiguere, did you ever find out how to change the contents of the object with jQuery? i've been looking around but had no joy. The problem is that it's such a bloody common word, "object"!!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.