473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DHTML question: DOM access to <OBJECT type="text/html" data="..." />

I recently learned how to do an <OBJECT> alternative to <IFRAME> in current
browsers using:

<object id="extendedhtml" type="text/html" data="otherpage.html" width="250"
height="400"></object>

My question is how do I access the document DOM of this object in
Javascript? For example, "alert(extendedhtml.innerHTML);" doesn't work and
produces an unknown error. I'd like to both read and write to the document's
body element's innerHTML property, as well as access its full DOM (forms,
etc) as I would access the elements of the main page.

Thanks,
Jon

PS Please do not tell me about server-side includes, suggest
document.writes, or belabor <IFRAME>. I'm just asking about document-loading
<OBJECT> tags, if anyone knows. Thanks.
Jul 23 '05 #1
6 5210


Jon Davis wrote:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current
browsers using:

<object id="extendedhtml" type="text/html" data="otherpage.html" width="250"
height="400"></object>

My question is how do I access the document DOM of this object in
Javascript? For example, "alert(extendedhtml.innerHTML);" doesn't work and
produces an unknown error. I'd like to both read and write to the document's
body element's innerHTML property, as well as access its full DOM (forms,
etc) as I would access the elements of the main page.


The W3C DOM is documented here:
http://www.w3.org/TR/DOM-Level-2-HTML/
with the HTMLObjectElement being documented here:
http://www.w3.org/TR/DOM-Level-2-HTM...tml#ID-9893177
so there you will see that according to that specification there is a
property
contentDocument
meaning in browsers implementing that specification you can acess
document.getElementById('extendedhtml').contentDoc ument
e.g. if you really want to access the innerHTML of the <body> element of
the document loaded in the <object>
var objDoc = document.getElementById('extendedhtml').contentDoc ument;
... objDoc.body.innerHTML ...
Only problem is that MSIE doesn't know contentDocument at all, its
documentation of <object> element is here
http://msdn.microsoft.com/library/de...cts/object.asp
It seems however that MSIE exposes the document inside of the <object>
via the property
object
so the code to work with MSIE and with DOM Level 2 browsers like Mozilla
or recent Opera 7 versions is:

<html lang="en">
<head>
<title>object scripting in MSIE and in DOM Level 2 HTML browsers</title>
<script type="text/javascript">
window.onload = function (evt) {
var obj;
if (document.getElementById && (obj =
document.getElementById('htmlObject1'))) {
var objDoc;
if (obj.contentDocument) {
objDoc = obj.contentDocument;
}
else if (obj.object) {
objDoc = obj.object;
}
if (objDoc && objDoc.body) {
alert(objDoc.body.innerHTML);
}
}
};
</script>
</head>
<body>
<p>
<object id="htmlObject1"
type="text/html"
data="jsInterpreter.html"
width="100%"
height="300"></object>
</p>
</body>
</html>

Crosspost and followup-to to comp.lang.javascript.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Jon Davis wrote:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current
browsers using:

<object id="extendedhtml" type="text/html" data="otherpage.html" width="250"
height="400"></object>

My question is how do I access the document DOM of this object in
Javascript?


Browser support for <object type="text/html" ...> is very poor. Are you
absoluty sure you want to switch from iframe to this ?
Jul 23 '05 #3
Pierre Goiffon <pg******@invalid.fr> wrote:
Browser support for <object type="text/html" ...> is very poor.


<panto>Oh no it isn't!</panto>

Supply width and height as attribute values and even IE supports it.

--
Spartanicus
Jul 23 '05 #4
Jon Davis wrote:
My question is how do I access the document DOM of this object
[snip]
PS Please do not tell me about server-side includes, suggest
document.writes, or belabor <IFRAME>.


"Get real! This is not a helpdesk, it's a discussion forum." etc.

--
Brian (remove "invalid" to email me)
Jul 23 '05 #5

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:41***********************@newsread2.arcor-online.net...


Jon Davis wrote:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using:

<object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object>

My question is how do I access the document DOM of this object in
Javascript? For example, "alert(extendedhtml.innerHTML);" doesn't work and produces an unknown error. I'd like to both read and write to the document's body element's innerHTML property, as well as access its full DOM (forms, etc) as I would access the elements of the main page.
The W3C DOM is documented here:
http://www.w3.org/TR/DOM-Level-2-HTML/
with the HTMLObjectElement being documented here:
http://www.w3.org/TR/DOM-Level-2-HTM...tml#ID-9893177
so there you will see that according to that specification there is a
property
contentDocument
meaning in browsers implementing that specification you can acess
document.getElementById('extendedhtml').contentDoc ument
e.g. if you really want to access the innerHTML of the <body> element of
the document loaded in the <object>
var objDoc = document.getElementById('extendedhtml').contentDoc ument;
... objDoc.body.innerHTML ...
Only problem is that MSIE doesn't know contentDocument at all, its
documentation of <object> element is here

http://msdn.microsoft.com/library/de...cts/object.asp It seems however that MSIE exposes the document inside of the <object>
via the property
object
so the code to work with MSIE and with DOM Level 2 browsers like Mozilla
or recent Opera 7 versions is:

<html lang="en">
<head>
<title>object scripting in MSIE and in DOM Level 2 HTML browsers</title>
<script type="text/javascript">
window.onload = function (evt) {
var obj;
if (document.getElementById && (obj =
document.getElementById('htmlObject1'))) {
var objDoc;
if (obj.contentDocument) {
objDoc = obj.contentDocument;
}
else if (obj.object) {
objDoc = obj.object;
}
if (objDoc && objDoc.body) {
alert(objDoc.body.innerHTML);
}
}
};
</script>
</head>
<body>
<p>
<object id="htmlObject1"
type="text/html"
data="jsInterpreter.html"
width="100%"
height="300"></object>
</p>
</body>
</html>

Crosspost and followup-to to comp.lang.javascript.

--

Martin Honnen
http://JavaScript.FAQTs.com/


Thank you, Martin.

I'm so sick of everyone else whining about how "this isn't a help desk",
etc. Martin, if you are interested, please e-mail me at
jo*@REMOVE.ME.powerblog.net for a free copy of PowerBlog if you want it.
Thanks for your help.

Cheers,
Jon Davis

PS This is an HTML DOM issue, not a JavaScript issue. JavaScript is not
necessarily browser-specific, and DOM is not necessarily related to
Javascript (in Internet Explorer, all ActiveX scripting languages apply,
including VBScript). You proved this by pointing to a W3C HTML DOM document
URL rather than a Javascript standard (ECMAScript) document URL. So I will
be posting here, not there, thank you.
Jul 23 '05 #6
On Sat, 18 Dec 2004 03:55:14 -0800, Jon Davis <jo*@REMOVE.ME.jondavis.net>
wrote:

[snip]
PS This is an HTML DOM issue, not a JavaScript issue. [...] So I will be
posting here, not there, thank you.


The comp.lang.javascript group covers various issues, not limited to
ECMAScript (and its derivatives). Browser DOMs are by far the most
frequently discussed topic. Scripting questions should be directed there,
or possibly alt.html or alt.html.dhtml.

As for it being on topic here in ciwah: you are wrong. As the name of the
group implies, questions should relate to authoring HTML for the Web
(<URL:http://www.stack.nl/~boris/HTML/ciwahfaq.html#p1>).

Mike
Please trim your quotations.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Arash Dejkam | last post by:
Hi All, Is it possible to write on an <OBJECT type="text/html"> using document.write() from within the html containing that tag the way we write on a popup window? I couldn't do that after a lot...
9
by: David D. | last post by:
Does the file extension matter when including a JavaScript file in an HTML page? Normally, one would include a JavaScript file in an HTML page using <script src="foo.JS" type="text/javascript">...
1
by: tilt | last post by:
Hello, I use an object element to replace the iframe element in ie, like this: <object id="x_obj" data="http://.../" type="text/html"> <iframe name="x_if" id="x_if"...
2
by: alxasa | last post by:
Hello, I am hoping someone can help me with this. I need a javascript function, which sits inside a <input type="text" name="firstname"> line of code. Now, if someone starts typing fine, but when...
3
by: joe | last post by:
Is it OK to have multiple: <script type="text/javascript" src="funcs1.js"></script> <script type="text/javascript" src="funcs2.js"></script> <script type="text/javascript"...
9
by: Steve | last post by:
Hi; I've being going through some legacy code on an old JSP site I have been patching. I noticed that when I save the JSP down to my PC as an HTML file I get this javascript error in IE 6 ( ...
2
by: Warren Tang | last post by:
Hello, everyone Can I make a <input type="text"tag transparent? I mean I can see through it and see the background of its container. Regards Warren
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.