justaguy wrote:
> On Monday, May 20, 2013 7:06:33 PM UTC-4, JJ wrote:
>> Assuming the "longtextstr" is not an Iframe, the code should be like
>> this.
>>
>> document.designMode = "on";
>>
>> document.execCommand('foreColor', false, '#ff0000');
^^^^^^^^
>> document.designMode = "off";
>
> Sorry for insufficient information previously.
> Yes, the longtextstr object/element is an iframe, and upon loading, it
> sets document.designMode = "on";
>
> Also, I had a typo (with quotes),
[word-wrapped at column 80]
> <input type="button" onclick="var sel
> =document.getElementById("longtextstr").contentWindow.getSelection();
> sel.execCommand('foreColor',false,'#ff0000');sel.select();"
> style="background-color:Red;width:25;height:23">
>
> should have been
> <input type="button" onclick="var sel
> =document.getElementById('longtextstr').contentWindow.getSelection();
> sel.execCommand('foreColor',false,'#ff0000');sel.select();"
> style="background-color:Red;width:25;height:23">
(Please learn to post properly. Do not use Google Groups for posting, it is
borken. See also <
http://jibbering.com/faq/#posting> and
<
http://PointedEars.de/faq#posting>.)
A “Selection” instance as returned by the getSelection() method and referred
here by “sel” still has not nor inherits an execCommand() or a select()
method, as the error console would have told you. The former is a method of
“(HTML)Document” instances, inherited from the Document prototype object.
The latter method I do not see existing at all in that context.
ISTM that the proprietary execCommand() API is generally incompatible with
the standards-compliant (W3C) Selection API. If you are using the Selection
API, you would have to use the properties of the returned object
(“baseNode”, “baseOffset”, “extentNode”, “extendOffset”, aso.), and DOM
Level 3 Core methods to split the text node in two and insert a
corresponding (“span”) element in-between.
Text formatting of selections is infinitely easier, but OTOH limited to the
commands that execCommand() supports, if you use the execCommand() API, as
e. g. the “foreColor” command will simply set the foreground color of the
selected portion of the document, provided designMode == "on". Another
important disadvantage of the execCommand() API is that at least in Chromium
26 it do text formatting by inserting a deprecated/invalid “font” element
instead of with a (“span”) element formatted by CSS.
Your Subject says “background color”, but you are using “foreColor” in the
code. Make up your mind.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.