0

我目前正在使用 Firefox 7.0.1。我一直在研究 WYSIWYG 编辑器,最近发现了在可编辑文档中嵌入内容的问题。我不确定这是否是一个错误,但是当文档具有 designMode=on 嵌入内容时,例如:

<object height="81" width="100%"> <param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F8921929"></param> <param name="allowscriptaccess" value="always"></param> <embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F8921929" type="application/x-shockwave-flash" width="100%"></embed> </object>

...页面中根本不显示。如果关闭设计模式,则内容显示得很好,但否则对象不会加载,并且几乎不可能围绕内容进行编辑,因为您看不到它在哪里。我可以构建一个占位符,但我更希望内容在正在编辑的文档中可见。这是我在 iframe 中用于编辑页面的基本文档:

var HTML = '<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body></body></html>';

以下是生成可编辑 iframe 文档的代码:

var editor = document.createElement('iframe');
document.getElementById(parent_id).appendChild(editor);

var editor_doc = editor.contentWindow.document || editor.contentDocument;
editor_doc.write(HTML);
editor_doc.close();

editor_doc.designMode =  "On";

这个问题有什么解决方案或解决方法吗?

4

1 回答 1

1

我最终通过解析嵌入、对象和参数标签来解决这个问题,并将数据放在 iframe 中,然后再将其添加到文档中。对于使用过渡文档类型的任何人来说,这都是一个极好的解决方案。

于 2011-11-08T12:59:10.130 回答