Re: IE - Insert newline into <pre>?
- From: "dhtmlkitchen@xxxxxxxxx" <dhtmlkitchen@xxxxxxxxx>
- Date: Sun, 30 Sep 2007 20:56:36 -0000
On Sep 26, 6:11 am, Julian Turner <julesb...@xxxxxxxxxxxxxx> wrote:
On 26 Sep, 04:35, "dhtmlkitc...@xxxxxxxxx" <dhtmlkitc...@xxxxxxxxx>I don't think it will work in my case; It's complicated to explain.
wrote:
[snip]> How can I insert \n into a pre and have it look right in IE?
[/snip]
I use Peter Michaux's solution of replacing the whole "pre" element
myself.
I hadn't though of Evertjan's solution of "<br>", which seems a good
one.
I've had success in some cases using \r\n:
String.nl = "clipboardData" in window ? "\r\n" : "\n";
But if I don't build the string myself, I don't have control over the
newline/cr characters.
I tried using Peter's approach which worked on PRE elements. I tried
getting it to work on TD but it didn't; so I sucked it up and used an
extra pre in those cases. anyone else reading this thread might be
interested.
/** This method will work with PRE but not TD elements
*/
function setInnerHTML( el, s ) {
if(! "innerHTML" in el ) {
throw new TypeError("setInnerHTML: first argument does not
support innerHTML. Is it an element?");
}
// Webkit and Futhark both support outerHTML.
// Only IE supports clipboardData
var outerHTML = el.outerHTML;
if( outerHTML && "clipboardData" in window ) {
var innerHTML = new RegExp(">([^<]*)<");
var oldContent = outerHTML.match(innerHTML)[1];
el.outerHTML = outerHTML.replace( oldContent, s );
}
else {
el.innerHTML = s;
}
}
Which works. Nasty code but it works.
The page will probably have other scripts that I don't control. The
solution doesn't address the possibility of an anomalous foreign
script that defines a clipboardData variable.
javascript:alert(Object.prototype.propertyIsEnumerable.call(window,
"clipboardData")); // JScript chokes on COM obj.
Attempting to find DontDelete by the return of delete
window.clipboardData was funny. Error: alert(error.name), TypeError:
Bad variable name.
Garrett
Julian Turner
.
- Follow-Ups:
- Re: IE - Insert newline into <pre>?
- From: Evertjan.
- Re: IE - Insert newline into <pre>?
- References:
- IE - Insert newline into <pre>?
- From: dhtmlkitchen@xxxxxxxxx
- Re: IE - Insert newline into <pre>?
- From: Julian Turner
- IE - Insert newline into <pre>?
- Prev by Date: Re: Recommendations for JavaScript drop-down menu code
- Next by Date: Re: I am having problems calling setTimeout with a function that has parameters
- Previous by thread: Re: IE - Insert newline into <pre>?
- Next by thread: Re: IE - Insert newline into <pre>?
- Index(es):
Relevant Pages
|
|