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

Discussion in 'Javascript' started by Arash Dejkam, Jul 19, 2004.

  1. Arash Dejkam

    Arash Dejkam Guest

    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.
     
    Arash Dejkam, Jul 19, 2004
    #1
    1. Advertising

  2. Arash Dejkam

    Rob Collyer Guest

    > 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 !
     
    Rob Collyer, Jul 19, 2004
    #2
    1. Advertising

  3. Arash Dejkam

    Rob Collyer Guest

    "Arash Dejkam" <> wrote in
    news::

    >
    > "Will Gittoes" <> wrote in message
    > news:...
    >> 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 !
     
    Rob Collyer, Jul 19, 2004
    #3
  4. Arash Dejkam

    Arash Dejkam Guest

    "Will Gittoes" <> wrote in message
    news:...
    > 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>
     
    Arash Dejkam, Jul 19, 2004
    #4
  5. 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-HTML/html.html#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/
     
    Martin Honnen, Jul 19, 2004
    #5
  6. 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/
     
    Martin Honnen, Jul 19, 2004
    #6
  7. Arash Dejkam

    Arash Dejkam Guest

    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" <> wrote in message
    news:40fba342$...
    >
    >
    > 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-HTML/html.html#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/
    >
     
    Arash Dejkam, Jul 19, 2004
    #7
  8. Arash Dejkam

    DU Guest

    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/author/dhtml/reference/properties/contentwindow.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 :)
     
    DU, Sep 29, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    569
    Guest
    Feb 20, 2004
  2. Damon Payne
    Replies:
    0
    Views:
    9,184
    Damon Payne
    Mar 8, 2005
  3. Replies:
    1
    Views:
    3,999
    =?Utf-8?B?Rng=?=
    Aug 16, 2005
  4. Arash Dejkam

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

    Arash Dejkam, Jul 19, 2004, in forum: HTML
    Replies:
    57
    Views:
    4,403
    Arash Dejkam
    Jul 22, 2004
  5. Jesús Bosch
    Replies:
    1
    Views:
    13,085
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 3, 2006
Loading...

Share This Page