By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,124 Members | 1,567 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,124 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
<por <divthat text is dynamically taken and added to? How would I
do this?

Oct 2 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
o.********@gmail.com wrote:
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
<por <divthat 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

--
Ian Collins.
Oct 2 '06 #2

P: n/a
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>Tex t has been
changed.</h1>"
}
</script>
<div id="text" onClick="nameout()">
Click on this text.
</div>
Ian Collins wrote:
o.********@gmail.com wrote:
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
<por <divthat 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

--
Ian Collins.
Oct 2 '06 #3

P: n/a
That won't always work... there are certain circumstances when
innerHTML is readonly. Look into DOM methods.

o.********@gmail.com wrote:
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>Tex t has been
changed.</h1>"
}
</script>
<div id="text" onClick="nameout()">
Click on this text.
</div>
Ian Collins wrote:
o.********@gmail.com wrote:
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
<por <divthat 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

--
Ian Collins.
Oct 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.