Flushing out text on a page? (Possibly simple AJAX question)

O

o.o.Pb.o.o

The title is pretty vague, I couldn't agree on how to word my inquiry
correctly, but I can explain. I'm writing a simple wiki script that is
contained in one HTML file (yes, it's been done before). I'm having
trouble with clearing anything displayed in the current document and
writing new text.
The primitive code (method calls and other needless stuff taken out)
I'm using goes as follows:

function showPage()
{
top.document.open();
top.document.write("");
top.document.close();
document.write("New Page");
}

On certain browsers, new text is simply displayed on the screen, all is
well. On Firefox and FF-based browsers, a completely new page is loaded
only containing the text "New Page" as its source. Everything else is
gone, a view source shows that "New Page" is the only contents of the
document. Of course, I need the rest of the code to run this script!

This is probably an exremely dumb question, but I don't know where to
begin looking for a solution. Is there any way that I could only have a
<p> or <div> that text is dynamically taken and added to? How would I
do this?
 
I

Ian Collins

The title is pretty vague, I couldn't agree on how to word my inquiry
correctly, but I can explain. I'm writing a simple wiki script that is
contained in one HTML file (yes, it's been done before). I'm having
trouble with clearing anything displayed in the current document and
writing new text.
The primitive code (method calls and other needless stuff taken out)
I'm using goes as follows:

function showPage()
{
top.document.open();
top.document.write("");
top.document.close();
document.write("New Page");
}

On certain browsers, new text is simply displayed on the screen, all is
well. On Firefox and FF-based browsers, a completely new page is loaded
only containing the text "New Page" as its source. Everything else is
gone, a view source shows that "New Page" is the only contents of the
document. Of course, I need the rest of the code to run this script!

This is probably an exremely dumb question, but I don't know where to
begin looking for a solution. Is there any way that I could only have a
<p> or <div> that text is dynamically taken and added to? How would I
do this?
Add a div to your document, give it an id. Find the div with
document.getElementById() and then either write the contents with
innerHTML or use DOM methods to add and remove text nodes
 
O

o.o.Pb.o.o

Thanks! That's exactly what I needed. Posting some sample code here for
any fellow noobs with the same question:

<script type="text/javascript">
function ()
{
document.getElementById('text').innerHTML="<h1>Text has been
changed.</h1>"
}
</script>
<div id="text" onClick="nameout()">
Click on this text.
</div>
 
A

agapeton

That won't always work... there are certain circumstances when
innerHTML is readonly. Look into DOM methods.
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top