SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Jan 2001
    Location
    Ottawa ON
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically make text appear on a web page

    I want to use Javascript to write text to a web page. I tried document.write and it appeared to make the text appear on its own on a new page, making the existing apge dissapear.

    I'm not really sure how document.writeln differs, but I don't think that I can specify where the text appears on the page if I use that.

    I think that using the innerhtml property is what I need, but I don't belive that it is supported by the DOM.

    What is the solution for printing text to an arbitrary spot on a page.

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put document.write or document.writeln in <script> tags where you want the text to go.

  3. #3
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've used the innerHTML function with IE but I don't know how well other browsers support it. Some simple code such as this should work:

    <html>
    <head>
    <script language="javascript">
    function myTest(newMessage) {
    document.all.sect1.style.color="red";
    document.all.sect1.innerHTML = newMessage ;
    }
    </script>
    </head>
    <body>
    <a href="#" onClick="myTest('This is my new message.')">click this</a><p />
    <div id="sect1"></div>
    </body>
    </html>

  4. #4
    SitePoint Guru
    Join Date
    Sep 1999
    Location
    Singapore
    Posts
    854
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    InnerHTML is also supported by Mozilla.

  5. #5
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, but document.all would need to be converted to document.getElementById

  6. #6
    SitePoint Addict
    Join Date
    Jan 2001
    Location
    Ottawa ON
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Anarchos
    Yep, but document.all would need to be converted to document.getElementById
    I don't know enough about JScript to understand why these differences occur, or the rational for having dfferences between the platforms. However, I understand that Mozilla is following the official ECMAScript plan and there must be a reason why the standard does not include Microsoft's conception of document.all. Does Microsoft have a plan to fully conform to the ECMAScript spec - will all of these issues between the browsers finally be over soon? (nevermind legacy issues ... )

  7. #7
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    IE 5 does support a lot of methods defined by W3C DOM, but Mozilla (NS 6's core) supports them all. IE 6 still doesn't support some of them, and I knwo it doesn't support the addEventListener. For more info on this, see my DHTML tutorial:

    www.pageresource.com/dhtml/ryan/

    aDog

  8. #8
    SitePoint Guru
    Join Date
    Sep 1999
    Location
    Singapore
    Posts
    854
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could be worthwhile to note that InnerHTML is not part of the official specs, but is supported in Mozilla by popular demand.

  9. #9
    SitePoint Addict
    Join Date
    Jan 2001
    Location
    Ottawa ON
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by duckie
    Could be worthwhile to note that InnerHTML is not part of the official specs, but is supported in Mozilla by popular demand.
    Which means that the specs are deficient?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •