Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19893

Re: How to make selected text (a range of a text block) with red background color?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.fsmpi.rwth-aachen.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <2165681.VknT3H6ZSX@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Tue, 21 May 2013 22:38:36 +0200
User-Agent KNode/4.10.2
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: How to make selected text (a range of a text block) with red background color?
Newsgroups comp.lang.javascript
References <eadac30e-3421-4f40-aa3b-e0dda2219b7a@googlegroups.com> <5725d024-62dd-482c-87cd-74bfabc4346d@googlegroups.com> <1coftckjl3uqg$.beu81uqlw7xz$.dlg@40tude.net> <9fcd2f49-405c-4286-aeb0-797536614c09@googlegroups.com>
MIME-Version 1.0
Lines 63
NNTP-Posting-Date 21 May 2013 22:40:15 CEST
NNTP-Posting-Host 96993931.newsspool4.arcor-online.net
X-Trace DXC=cfFWIG34@1g016@cHD@m;j4IUK<Cl32<a4Fo<]lROoRa8kF<OcfhCOk7EWL1O4@eWkDZm8W4\YJNlb@mF9jNikde7a5\<`>]gfn=ONK;;5T2\i
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:19893

Show key headers only | View raw


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.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

How to make selected text (a range of a text block) with red background color? justaguy <lichunshen84@gmail.com> - 2013-05-19 12:20 -0700
  Re: How to make selected text (a range of a text block) with red background color? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-05-19 14:04 -0700
    Re: How to make selected text (a range of a text block) with red background color? justaguy <lichunshen84@gmail.com> - 2013-05-19 14:47 -0700
      Re: How to make selected text (a range of a text block) with red background color? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-05-19 15:24 -0700
  Re: How to make selected text (a range of a text block) with red background color? Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-05-19 14:22 -0700
    Re: How to make selected text (a range of a text block) with red background color? justaguy <lichunshen84@gmail.com> - 2013-05-19 15:58 -0700
      Re: How to make selected text (a range of a text block) with red background color? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-05-19 16:05 -0700
        Re: How to make selected text (a range of a text block) with red background color? justaguy <lichunshen84@gmail.com> - 2013-05-19 17:59 -0700
          Re: How to make selected text (a range of a text block) with red background color? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-05-19 18:45 -0700
  Re: How to make selected text (a range of a text block) with red background color? justaguy <lichunshen84@gmail.com> - 2013-05-19 14:50 -0700
    Re: How to make selected text (a range of a text block) with red background color? JJ <duh@nah.meh> - 2013-05-21 06:06 +0700
      Re: How to make selected text (a range of a text block) with red background color? justaguy <lichunshen84@gmail.com> - 2013-05-21 10:05 -0700
        Re: How to make selected text (a range of a text block) with red background color? JJ <duh@nah.meh> - 2013-05-22 00:54 +0700
          Re: How to make selected text (a range of a text block) with red background color? justaguy <lichunshen84@gmail.com> - 2013-05-21 21:25 -0700
        Re: How to make selected text (a range of a text block) with red background color? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-21 22:38 +0200

csiph-web