Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using TextContent and retaining white space

1,708 views
Skip to first unread message

GrandNagel

unread,
Jul 6, 2007, 1:20:06 PM7/6/07
to
I have a routine that "turns" a DIV tag into a TEXTAREA. I am able to
extract the innerText(ie)/textContent(ff). In IE the retrieved text
retains its whitespace, but in FFox it does not. I have tried setting
the whiteSpace style attribute before copying it to "pre", but that
provides no benefit (possibly because the rendering might only be done
after my JS routine returns..?)

Is there any way to retain line breaks and white space when asking the
browser to return the textContent from JS in ffox?

thx,

D.

heres what I've tried so far...

function MakePlainText(el)
{
el.style.whiteSpace="pre"
tmp = document.all ? el.innerText : el.textContent
alert(tmp) // the whitespace and breaks are already gone
by here in ffox.
tmp = tmp.replace(/[\n]/gi,'\n\n')
alert(tmp)
tmp = tmp.replace(/(Plain Text)/gi,'')
el.innerHTML = '<textarea READONLY style="width:100%;"
rows="20">' + tmp.replace(/[\n\r][\n\r][\n\r][\n\r][\n\r]/gi,'') + '</
textarea>'
//alert(el.id.split('TARGET')[0])
window.location.href="#" + el.id.split('TARGET')[0]
}

GrandNagel

unread,
Jul 6, 2007, 1:27:08 PM7/6/07
to

I have found this and my though is I'm screwed...

textContent of type DOMString, introduced in DOM Level 3
This attribute returns the text content of this node and its
descendants. When it is defined to be null, setting it has no effect.
On setting, any possible children this node may have are removed and,
if it the new string is not empty or null, replaced by a single Text
node containing the string this attribute is set to.
On getting, no serialization is performed, the returned string
does not contain any markup. No whitespace normalization is performed
and the returned string does not contain the white spaces in element
content (see the attribute Text.isElementContentWhitespace).
Similarly, on setting, no parsing is performed either, the input
string is taken as pure textual content.
The string returned is made of the text content of this node
depending on its type, as defined below:

Any thoughts?

0 new messages