Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get html elements from an object tag?

I'm using the object tag to load an html snippet within an html page.

My code looks something along these lines:

<html><object data="/html_template"></object></html>

As expected after the page is loaded some elements are added between the object tags. I want to get those elements but I can't seem to access them.

I've tried the following $("object").html() $("object").children() $("object")[0].innerHTML

None of these seem to work. Is there another way to get those elements?

EDIT:

A more detailed example:

consider this

<html><object data="http://www.YouTube.com/v/GGT8ZCTBoBA?fs=1&hl=en_US"></object></html>

If I try to get the html within the object I get an empty string.

http://jsfiddle.net/wwrbJ/1/

like image 413
Noam Avatar asked Jan 10 '12 04:01

Noam


People also ask

How do you access data from an object in HTML?

Just copy the html and js code and it should work for you. Just make sure you create the appropriate txt or html file for the object to import.

What can be done with an object tag *?

The <object> tag is an HTML tag and used to display multimedia like audios, videos, images, PDFs, and Flash in web pages. It can also be used for displaying another webpage inside the HTML page. The <param> tag is also used along with this tag to define various parameters.

Can I use object tag?

The <object> tag defines an embedded object within an HTML document. Use this element to embed multimedia (like audio, video, Java applets, ActiveX, PDF, and Flash) in your web pages. You can also use the <object> tag to embed another webpage into your HTML document.


2 Answers

As long as you place it on the same domain you can do the following:

HTML

<html>     <object id="t" data="/html_template" type="text/html">     </object> </html> 

JavaScript

var t=document.querySelector("#t"); var htmlDocument= t.contentDocument; 
like image 99
blabla Avatar answered Sep 29 '22 17:09

blabla


The innerHTML will provid access to the html which is in between the <object> and </object>. What is asked is how to get the html loaded by the object inside the window/frame that it is producing (it has nothing to do with the code between the open and close tags).

I'm also looking for an answer to this and I'm afraid there is none. If I find one, I'll come back and post it here but I'm looking (and not alone) for a lot of time now.

like image 26
georgosn Avatar answered Sep 29 '22 15:09

georgosn