Building a WYSIWYG HTML Editor Part 1/2 - Building our HTML editor (contd.) (Page 5 of 7 )
What good is a web site that has just boring old black text and a white background? Luckily execCommand has two commands that we can use to change the color of text and the background. These commands are forecolor and backcolor.
As you can see in the code above, the foreground color is grabbed from a call to prompt() and passed in as the third argument to execCommand.
One of the things that amazed me when I started playing around with the execCommand method was that when you pass the "createlink" command to it, IE displays a modal window that looks like this:
Here are two different version of the link: the first one links a piece of text, and the second one is just the URL:
Nothing new here, we simply use prompt() to get the URL of the image and pass it as the value to execCommand. The URL can be local or remote. Here's a screen shot:
One good thing about our HTML editor is that once you insert a horizontal rule (or any other control), you can change its properties very easily. For example, if I wanted to change its color, I would click on it and then click on the foreground color button, enter "green", and the color of the horizontal rule would change to green.