Avatar billede holmqvist Nybegynder
21. februar 2006 - 13:57 Der er 4 kommentarer

WYSIWYG editor

I use the execCommand function in javascript to build a WYSIWYG editor where you can write text, format it, change HTML-source behind and so on..

Now I want it to work as Word, meaning: when the cursor is placed on some text, the appropriate buttons will be pushed down (this text is: Bold, Underlined, size..).
How do I get the tags that affect the text and what event can I use (should be changed everytime user clicks or moves the cursor with arrows) ??

/ Jacob
Avatar billede plazm Nybegynder
21. februar 2006 - 23:54 #1
You could use
queryCommandState("bold") to get the state of commands which only have on and off and
queryCommandValue("fontsize") to get the value of commands which has more than one option.
Avatar billede holmqvist Nybegynder
23. februar 2006 - 15:54 #2
I was building a bit more complicated solution using TextRange and parentElement() to find out the tags, that would have been perfect if it wasn't for the very strange and buggy behavior that moveToElementText() function is displaying..

Your functions was a lot easier to use and seems more reliable, but is there any way to detect eg images and hyperlinks with them? (or something else) They worked great on bold,italic,underline,font etc, but I haven't found any solution for non-text-stuff
Avatar billede plazm Nybegynder
23. februar 2006 - 16:17 #3
Well, im working on my own wysiwyg editor, and i've the same problem. Im working on it, and will return here, if i find a solution.
Avatar billede horsmark Nybegynder
27. marts 2006 - 19:28 #4
please take a look on the following editor (crossbrowser)
http://tinymce.moxiecode.com/
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester