How to undo a highlighted area in an iFrame?

2013-08-07 3:31 pm
I am currently working on a DIY WYSIWYG text editor using javascript.
One of the button is to highlight the selected text into yellow color, with the code (in the function):
rtf.document.execCommand('backColor', false, "#FFFF00");
It works fine, but I want that, if the button is clicked again, any highlighted area will be "unhighlighted", which I think of something like this:

var current_text = window.frames['rtf'].document.body.innerHTML;
rtf.document.execCommand('backColor', false, "#FFFF00");
if (window.frames['rtf'].document.body.innerHTML == current_text) {
rtf.document.execCommand('backColor', false, "");
alert('testing');
}

When I selected a highlighted area and press the button, the "testing" alert did show up, but the selected text was not "unhighlighted". And I could search for ways that execCommand('backColor') can "unhighlight" a piece of text.

Anyone can help?

回答 (1)

2013-08-15 11:32 am
✔ 最佳答案
Remove the code that caused the highlight.


收錄日期: 2021-04-13 19:37:07
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20130807073147AAsSDZa

檢視 Wayback Machine 備份