【问题标题】:IE exec command rich text editingIE exec 命令富文本编辑
【发布时间】:2009-10-07 18:02:16
【问题描述】:

我想在 WYSIWYG 编辑器中插入图像,但我无法在 Internet Explorer(6/7) 中插入图像,尽管它在 Firefox 中运行良好。它失败而没有抛出任何错误。

这是我正在使用的:

execCommand('insertImage', false, 'absolute/path/to/an/image');

【问题讨论】:

    标签: javascript internet-explorer richtextediting


    【解决方案1】:

    感谢您的回答,但事实证明我的问题出现了,因为如果我的 iframe(richeditor 容器)没有焦点,IE 无法插入图像。因此,我在尝试使用 execCommand 之前使用了以下代码,并且成功了。

    document.getElementById('iframeId').contentWindow.focus();
    

    【讨论】:

    • 它有效!!!! IE 快把我逼疯了!好多啊!只是告诉你两年前的信息仍然有用:)
    【解决方案2】:

    在 IE 中,execCommand 存在于文档对象上,而不是窗口对象上。 (好吧,它也存在于范围对象上,但无论如何。)

    试试:

    document.execCommand("insertImage", false, "absolute/path/to/an/image");
    

    【讨论】:

      猜你喜欢
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      • 2019-12-25
      • 2023-03-20
      • 1970-01-01
      相关资源
      最近更新 更多