Re: IE - Insert newline into <pre>?



On Sep 26, 6:11 am, Julian Turner <julesb...@xxxxxxxxxxxxxx> wrote:
On 26 Sep, 04:35, "dhtmlkitc...@xxxxxxxxx" <dhtmlkitc...@xxxxxxxxx>
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 don't think it will work in my case; It's complicated to explain.
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


.



Relevant Pages

  • RE: text truncation in dropdownlist control
    ... Thanks for the followup and your understanding. ... encapsulated control rather than a certain control with lots of scripts ... Thanks & Regards, ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: ie dynamic rendering feature
    ... To consume the scripts on a control add ... // public class SomeExtender: ... ... Only the target panel exists on the server, all other divs are created on ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: command line vs grid control
    ... get grid control; ... If your scripts cover your requirements, ... The fact that their code is tested: Oracle wins ...
    (comp.databases.oracle.server)
  • Re: Non-JMS Scripts
    ... played to slimy perfection by Keith Szarabajka. ... even if he can't sell us the scripts. ... contrariwise, no amount of force can control a free man, a man whose mind ...
    (rec.arts.sf.tv.babylon5.moderated)
  • New thread RDSL, post-2.6.20 kernels and amanda (tar) miss-fires
    ... I now have my scripts more or less under control, and I can report that ... kernel-2.6.20.1 with no other patches does not exhibit the undesirable ...
    (Linux-Kernel)