WYSIWYG editor for IE [closed]

限于喜欢 提交于 2019-12-18 09:40:06

问题


I want to make a new WYSIWYG editor, in which I have used an Iframe with designmode ON, I Want to do something like - when user selects a text and click an image button the image should be in background of the text and the image should be toggle


回答1:


The InsertHTML command does not work in IE. However, IE's TextRange object has a convenient pasteHTML() method that you can use instead.

Live demo: http://jsfiddle.net/RmXgy/1/

Code:

function getSelectedText() {
    var selectedText = "", sel;
    if (window.getSelection) {
        selectedText = "" + window.getSelection();
    } else if ( (sel = document.selection) && sel.type == "Text") {
        selectedText = sel.createRange().text;
    }
    return selectedText;
}

var sel, html = '<span style="background-image: url(foo.png)">'
         + getSelectedText() + "</span>";

if ( (sel = document.selection) && sel.type != "Control") {
    sel.createRange().pasteHTML(html);
} else {
    document.execCommand("InsertHTML", false, html);
}


来源:https://stackoverflow.com/questions/8739711/wysiwyg-editor-for-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!