IE的WYSIWYG编辑器 [英] WYSIWYG editor for IE

查看:70
本文介绍了IE的WYSIWYG编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个新的WYSIWYG编辑器,我在其中使用了设计模式为ON的Iframe,我想做类似的事情 - 当用户选择文本并单击图像按钮时,图像应该在文本的背景中,图像应该切换

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

推荐答案

InsertHTML 命令不起作用IE浏览器。但是,IE的 TextRange 对象有一个方便的 pasteHTML()方法,你可以使用它。

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

现场演示: http://jsfiddle.net/RmXgy/1/

代码:

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);
}

这篇关于IE的WYSIWYG编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆