472,789 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 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 5142


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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.