Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Write on <OBJECT type="text/html"> ?

Reply
Thread Tools

Write on <OBJECT type="text/html"> ?

 
 
Arash Dejkam
Guest
Posts: n/a
 
      07-19-2004
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 of try.

Thanks in advance.


 
Reply With Quote
 
 
 
 
Rob Collyer
Guest
Posts: n/a
 
      07-19-2004
> Arash Dejkam wrote:
>> 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 of try.
>>
>> Thanks in advance.


Yes it is possible to output any type of mark-up at run-time using document.write.

--
Robert Collyer
www.webforumz.com
Free Web Design and Development Help, Discussions, tips and Critique!
ASP, VB, .NET, SQL, CSS, HTML, Javascript, Flash, XML, SEO !
 
Reply With Quote
 
 
 
 
Rob Collyer
Guest
Posts: n/a
 
      07-19-2004
"Arash Dejkam" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

>
> "Will Gittoes" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Arash Dejkam wrote:
>> > 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 of try.
>> >
>> > Thanks in advance.
>> >
>> >

>>
>> Remember, you can use single quotes as well.
>>
>> document.write("<OBJECT type='text/html'>")
>> | |
>> Single quotes----------------+---------+
>>
>> Don't cross-post, please.

>
> You didn't get the point.
> I don't want to write on my html but on the object frame itself,
> something like this:
>
> <object id="foo" type="text/html" />
> <script>
> foo.document.write("Hello World!");
> </script>
>
>
>


What exactly are you trying to achieve?

There must be a better way, than the way you are approching this.

--
Robert Collyer
www.webforumz.com
Free Web Design and Development Help, Discussions, tips and Critique!
ASP, VB, .NET, SQL, CSS, HTML, Javascript, Flash, XML, SEO !
 
Reply With Quote
 
Arash Dejkam
Guest
Posts: n/a
 
      07-19-2004

"Will Gittoes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Arash Dejkam wrote:
> > 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 of try.
> >
> > Thanks in advance.
> >
> >

>
> Remember, you can use single quotes as well.
>
> document.write("<OBJECT type='text/html'>")
> | |
> Single quotes----------------+---------+
>
> Don't cross-post, please.


You didn't get the point.
I don't want to write on my html but on the object frame itself, something
like this:

<object id="foo" type="text/html" />
<script>
foo.document.write("Hello World!");
</script>


 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      07-19-2004


Arash Dejkam wrote:


> 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 of try.


You can do in Netscape 7, Mozilla and Opera 7 using the contentDocument
at least but it doesn't work in IE(5/6):

<html lang="en">
<head>
<title>the document object of an embedded object</title>
<script type="text/javascript">
function initObject () {
var object, objDoc;
if (document.getElementById && (object =
document.getElementById('anObject'))) {
if (object.contentDocument) {
objDoc = object.contentDocument;
}
else if (object.contentWindow) {
objDoc = object.contentWindow.document;
}
if (objDoc) {
initDoc(objDoc);
}
}
}

function initDoc (doc) {
doc.open();
doc.write([
'<html><head><title>document.written content<\/title><\/head>',
'<body><p>Kibology for all.<\/p><\/body><\/html>'
].join('\r\n'));
doc.close();
}

window.onload = function (evt) {
initObject();
};
</script>
</head>
<body>
<p>
Here is the object:
<object type="text/html" id="anObject"
width="200" height="200"
data="about:blank"></object>
</p>
</body>
</html>

Can anyone report back whether the above writes to the object document
with Safari or Konqueror?

contentDocument is specified in the W3C DOM Level 2 HTML, see
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-38538621
so newer browser like Safari or Konqueror should support it.

But if you want to embed text/html and access its document then simply
go for
<iframe name="iframeName" ...></iframe>
and then you should have no trouble in browsers since IE4, Opera 6,
Netscape 6 etc accessing
window.frames.iframeName.document
with script.

--

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

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      07-19-2004


Arash Dejkam wrote:


> bad news it doesn't work in IE!, by the way, I tested your code in Opera
> 7.01 Build 2651 and it DIDN'T work!


One reason more to go for the iframe. Sorry for not being more specific
about Opera, I had only tested with Opera 7.50 on Windows and as I don't
use <object> myself to render text/html I had no knowledge about details
of Opera support for contentDocument.


> but worked in mozilla. I can't use
> IFRAME because my page should be XHTML1.0 Strict.


It is your decision, if that document type is important to you then you
can't use iframe but currently with the browsers around if you are
interested in consistent and reliable use and scripting then iframe is
much better than object.

--

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

 
Reply With Quote
 
Arash Dejkam
Guest
Posts: n/a
 
      07-19-2004
Thanks Martin!

bad news it doesn't work in IE!, by the way, I tested your code in Opera
7.01 Build 2651 and it DIDN'T work! but worked in mozilla. I can't use
IFRAME because my page should be XHTML1.0 Strict.

Arash

"Martin Honnen" <(E-Mail Removed)> wrote in message
news:40fba342$(E-Mail Removed)...
>
>
> Arash Dejkam wrote:
>
>
> > 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 of try.

>
> You can do in Netscape 7, Mozilla and Opera 7 using the contentDocument
> at least but it doesn't work in IE(5/6):
>
> <html lang="en">
> <head>
> <title>the document object of an embedded object</title>
> <script type="text/javascript">
> function initObject () {
> var object, objDoc;
> if (document.getElementById && (object =
> document.getElementById('anObject'))) {
> if (object.contentDocument) {
> objDoc = object.contentDocument;
> }
> else if (object.contentWindow) {
> objDoc = object.contentWindow.document;
> }
> if (objDoc) {
> initDoc(objDoc);
> }
> }
> }
>
> function initDoc (doc) {
> doc.open();
> doc.write([
> '<html><head><title>document.written content<\/title><\/head>',
> '<body><p>Kibology for all.<\/p><\/body><\/html>'
> ].join('\r\n'));
> doc.close();
> }
>
> window.onload = function (evt) {
> initObject();
> };
> </script>
> </head>
> <body>
> <p>
> Here is the object:
> <object type="text/html" id="anObject"
> width="200" height="200"
> data="about:blank"></object>
> </p>
> </body>
> </html>
>
> Can anyone report back whether the above writes to the object document
> with Safari or Konqueror?
>
> contentDocument is specified in the W3C DOM Level 2 HTML, see
> http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-38538621
> so newer browser like Safari or Konqueror should support it.
>
> But if you want to embed text/html and access its document then simply
> go for
> <iframe name="iframeName" ...></iframe>
> and then you should have no trouble in browsers since IE4, Opera 6,
> Netscape 6 etc accessing
> window.frames.iframeName.document
> with script.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/
>



 
Reply With Quote
 
DU
Guest
Posts: n/a
 
      09-29-2004
Martin Honnen wrote:
>
>
> Arash Dejkam wrote:
>
>
>> 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 of try.

>
>
> You can do in Netscape 7, Mozilla and Opera 7 using the contentDocument
> at least but it doesn't work in IE(5/6):
>
> <html lang="en">
> <head>
> <title>the document object of an embedded object</title>
> <script type="text/javascript">
> function initObject () {
> var object, objDoc;
> if (document.getElementById && (object =
> document.getElementById('anObject'))) {
> if (object.contentDocument) {
> objDoc = object.contentDocument;
> }
> else if (object.contentWindow) {



contentWindow can not apply to HTML object element
http://msdn.microsoft.com/workshop/a...tentwindow.asp


> objDoc = object.contentWindow.document;
> }



> if (objDoc) {
> initDoc(objDoc);
> }
> }
> }
>
> function initDoc (doc) {
> doc.open();
> doc.write([
> '<html><head><title>document.written content<\/title><\/head>',
> '<body><p>Kibology for all.<\/p><\/body><\/html>'
> ].join('\r\n'));
> doc.close();



or

var objParg = doc.createElement("p");
objParg.appendChild(doc.createTextNode("Kibology for all."));
doc.body.appendChild(objParg);
since blank document have a body node.

> }
>
> window.onload = function (evt) {
> initObject();


Isn't that asking for trouble? Like asynchronous onload events for
window and document body?

> };



DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.3
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use Response.write to write to a specific area on a aspx pa =?Utf-8?B?QWJlbCBDaGFu?= ASP .Net 6 05-03-2006 10:16 PM
DVD Write speed - Not able to write at 8 speed Vincent Wonnacott Computer Support 1 09-16-2004 03:14 PM
write a union object using write JasBascom C++ 1 02-24-2004 08:18 AM
How to open a new console and write something out write printf() Peter Hansen C++ 1 08-24-2003 11:49 AM
How to open a new console and write something out write printf() Peter Hansen C Programming 1 08-24-2003 11:49 AM



Advertisments