Object tag to write HTML page to via JavaScript?

G

gsb

Object tag to write HTML page to via JavaScript?

I've used iFrames and Objects to load web pages into another page.
I want to do similar but not load a uri, rather write the page, <HTML>
....to...</HTML> via a JavaScript function.
Is this possible with either of these two tags?

Thanks,

gsb
 
L

Lasse Reichstein Nielsen

gsb said:
Object tag to write HTML page to via JavaScript?

I've used iFrames and Objects to load web pages into another page.
I want to do similar but not load a uri, rather write the page, <HTML>
...to...</HTML> via a JavaScript function.
Is this possible with either of these two tags?

Use an iframe.
---
<iframe id="foo" name="foo"></iframe>

<script type="text/javascript">
function writeDoc() {
var doc = frames['foo'].document;
doc.open();
doc.write("<!DOCTYPE ... ><html> ....funny content! </html>");
doc.close();
}
</script>
<input type="button" value="insert" onclick="writeDoc()">
---
Tested in IE 6, Mozilla FB and Opera 7.
Mozilla is the one that requires the name attribute on the iframe
in order to access it through the frames collection.

/L
 
G

gsb

Does that work with an object, or just an iFrame?

Thanks again,

gsb

Lasse Reichstein Nielsen said:
gsb said:
Object tag to write HTML page to via JavaScript?

I've used iFrames and Objects to load web pages into another page.
I want to do similar but not load a uri, rather write the page, <HTML>
...to...</HTML> via a JavaScript function.
Is this possible with either of these two tags?

Use an iframe.
---
<iframe id="foo" name="foo"></iframe>

<script type="text/javascript">
function writeDoc() {
var doc = frames['foo'].document;
doc.open();
doc.write("<!DOCTYPE ... ><html> ....funny content! </html>");
doc.close();
}
</script>
<input type="button" value="insert" onclick="writeDoc()">
---
Tested in IE 6, Mozilla FB and Opera 7.
Mozilla is the one that requires the name attribute on the iframe
in order to access it through the frames collection.

/L
 
L

Lasse Reichstein Nielsen

Please don't top post.
Does that work with an object, or just an iFrame?

Probably only with iframes. It accesses the document object
of the embedded page throught the frames collection.

I don't have much experience with objects, but my impression is
that pages embedded with the object tag are not easily accessible
through scripting - because the object can hold so many different
types of data, there is no simple way to access the data that is
there.

/L
 
G

gsb

I appreciate your patience, but I'm not sure what "Please don't top post."
means.
Please explain. I apologies for my ignorance regarding the posting.

I like the simplicity of your solution, but it did not work in Netscape (I
have 7.1)
That is why I asked about the object tag.

Thanks,

gsb
 
L

Lasse Reichstein Nielsen

gsb said:
I appreciate your patience, but I'm not sure what "Please don't top
post." means. Please explain. I apologies for my ignorance
regarding the posting.

Top posting refers to the practice of putting ones entire reply at
the top of the message, and including the entire previous message
below. It is a bad idea for several reasons.

1) Readability. While this can ofcourse be argued, a majority of
newsgroup users prefer to see the context of a reply before the reply.
Splitting the replies to different parts of the previous message up,
also makes it easier to see which reply replies to which part.

2) Bandwidth. Including the entire previous message below is a waste
of bandwidth. While a single message won't kill anyone, not even
people reading news on a modem and paying by the minute, if two people
both use this quoting style in reply to each other, the quotes would
quickly become huge (each message including the *entire* history of
the discussion). It is recommended to quote only the parts of the
previous message that are needed to give context to your reply.
Keeping quotes from even earlier messages is rarely improtant,
and should be kept to a minimum.
(Not quoting anything is also bad, because you completely lose the
context).

3) Structure. The standard for messages specifies a separator between
the message and the signature (minus-minus-space on a line of its
own). Message readers recognize this divider, and treats the part
below it specially. By writing the reply at the top, the entire quoted
message now appears below the signature separator, which can be highly
confuzing to both people and newsclients. The only advantage is that
clients should cut the signature before replying, potentially avoiding
the extra quoting. Sadly, not all clients does this.

Thank you for asking :)
I like the simplicity of your solution, but it did not work in Netscape (I
have 7.1)

It works for me in Netscape 7.1 (freshly installed - damn them for
installing AOL without my permission!).
That is why I asked about the object tag.

Actually, in Netscape 7.1 it seems to work with object instead of iframe.
It doesn't in Opera or IE, though.

/L
 
G

gsb

Thank you for responding.
My internet express auto add that stuff in the reply.

Anyway, here's what I came up with:

function doWrite() {
var doc=null, obj=document.getElementById( "myID" );
if(obj.contentDocument) doc=obj.contentDocument;
else if(obj.contentWindow) doc=obj.contentWindow.document;
else if(obj.document) doc=obj.document;
// else I'm scewed - LOL
...
str = "whatever";
...
doc.open();
doc.write(str);
doc.close();
}

Works in IE6 and Netscape 7.1; don't know about the others.

Thanks for your help and patience.

gsb
 
L

Lasse Reichstein Nielsen

AOL or AIM? NS7 comes with the AOL IM service but I have never known it to
install the full blown AOL application.

Actually, just an advertisment for AOL. I was thinking of AIM, but it
seems it worked to deselect it before installation. So, no that damn
was not deserved. Now they just get one for putting advertising on my
desktop :)

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top