execCommand, and selected text..

P

PSiegmann

Hi newsgroup.

I have a question about execCommand and the "current selection":

http://www.mozilla.org/editor/midas-spec.html

from the above website: (about the execCommand)

(under "supported commands->bold")

"If there is no selection, the insertion point will set bold for
subsequently typed characters.

If there is a selection and all of the characters are already bold,
the bold will be removed. Otherwise, all selected characters will
become bold."

---

Now, my question is.. how to make a selection?

I use the following code:

<html>
<head>
<title></title>
<script language="javascript">



window.onload = function()
{

var rted = document.getElementById("rte").contentWindow.document;

rted.designMode = "On";
rted.open();
rted.write('<html><head></head><body>Some preloaded <b>content</b></
html>');
rted.close();
}


function ABC()
{
var rted = document.getElementById("rte").contentWindow;
rted.focus();

rted.document.execCommand('bold', false);


}

</script>



</head>
<body>

<span onclick="javascript: onClick=ABC();">ABC</span>

<br>
<br>

<iframe id="rte"></iframe>

</body>
</html>



The problem in that, is, if I select a text in the Iframe, and click
on the span, the text will not get bold. The selected text that is,
but, if I start to type a new text into the iframe, that new text is
bold. If I click on the span tag again, new entered text will not be
bold.

So, it works "in general", but not on marked text. How to make it work
on marked, i.e. selected text?
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top