Determining marked text

A

Aaron Gray

In theses JavaScript WYSIWYG editors how do they determine if and where
there is marked (highlighted) text ?

Many thanks in advance,

Aaron
 
M

Martin Honnen

Aaron said:
In theses JavaScript WYSIWYG editors how do they determine if and where
there is marked (highlighted) text ?

Mozilla exposes a proprietary selection object as a result of
window.getSelection() e.g.
var selection = window.getSelection();
If you simply want the text then all you need is
selection.toString()
but that object has an API with properties and methods and is composed
of W3C DOM ranges you can manipulate, see
<http://xulplanet.com/references/objref/Selection.html>

IE/Win has its own different proprietary selection and range API, see
<http://msdn.microsoft.com/library/d...hor/dhtml/reference/objects/obj_selection.asp>
 
J

Julian Turner

Aaron said:
In theses JavaScript WYSIWYG editors

Any one in particular?
how do they determine if and where
there is marked (highlighted) text ?

Do you mean selected text? If not, what do you mean by "highlighted"?

If you mean selected text, then the text selection functionality, and
indeed the basic editor functionality, is not provided by JavaScript at
all, but by the browser itself.

The browsers vary as to their implementations of WYSIWG (or rich-text)
editing, with Internet Explorer and Firefox perhaps being the most
advanced at present.

You can access the selection, and can access various editor commands,
through host objects exposed to JavaScript by the browser.

For instance, Internet Explorer has the "document.selection" and
"TextRange" objects, using which you can access the current selected
text, and execute commands, such as apply bold.

Firefox (and Mozilla) have their own selection object:-

E.g. see
<URL:http://developer.mozilla.org/en/docs/window.getSelection>
Many thanks in advance,

Hope that helps.

Regards

Julian Turner
 
A

Aaron Gray

In theses JavaScript WYSIWYG editors
Any one in particular?

There are quite a few now, cannot remember right now but I could make a list
of the ones I have seen if you want.
Do you mean selected text? If not, what do you mean by "highlighted"?

Yes, selected.
If you mean selected text, then the text selection functionality, and
indeed the basic editor functionality, is not provided by JavaScript at
all, but by the browser itself.
Right

The browsers vary as to their implementations of WYSIWG (or rich-text)
editing, with Internet Explorer and Firefox perhaps being the most
advanced at present.

This is great.
You can access the selection, and can access various editor commands,
through host objects exposed to JavaScript by the browser.

For instance, Internet Explorer has the "document.selection" and
"TextRange" objects, using which you can access the current selected
text, and execute commands, such as apply bold.

Firefox (and Mozilla) have their own selection object:-

E.g. see
<URL:http://developer.mozilla.org/en/docs/window.getSelection>

Rich text editting, nice :)
Hope that helps.

Yep. Thanks alot,

Aaron
 
A

Aaron Gray

In theses JavaScript WYSIWYG editors how do they determine if and where
Mozilla exposes a proprietary selection object as a result of
window.getSelection() e.g.
var selection = window.getSelection();
If you simply want the text then all you need is
selection.toString()
but that object has an API with properties and methods and is composed of
W3C DOM ranges you can manipulate, see
<http://xulplanet.com/references/objref/Selection.html>

IE/Win has its own different proprietary selection and range API, see
<http://msdn.microsoft.com/library/d...hor/dhtml/reference/objects/obj_selection.asp>

Thanks,

Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top