Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19874
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2013-05-21 10:05 -0700 |
| References | <eadac30e-3421-4f40-aa3b-e0dda2219b7a@googlegroups.com> <5725d024-62dd-482c-87cd-74bfabc4346d@googlegroups.com> <1coftckjl3uqg$.beu81uqlw7xz$.dlg@40tude.net> |
| Message-ID | <9fcd2f49-405c-4286-aeb0-797536614c09@googlegroups.com> (permalink) |
| Subject | Re: How to make selected text (a range of a text block) with red background color? |
| From | justaguy <lichunshen84@gmail.com> |
On Monday, May 20, 2013 7:06:33 PM UTC-4, JJ wrote:
> On Sun, 19 May 2013 14:50:09 -0700 (PDT), justaguy wrote:
>
> > I should add (forgive me for top posting).
>
> >
>
> > That the following code fails (does not do anything and no error), tested
>
> > with Firefox 20.
>
> >
>
> > <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"
>
> > />
>
>
>
> contentWindow property is for IFrame and Object elements only, and
>
> execCommand is a method of the document object only.
>
>
>
> The document.designMode should be set to "on" before using execCommand that
>
> modifies the document content, and set it back to "off" after all
>
> modifications are done.
>
>
>
> 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),
<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">
Thanks.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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