designMode=on 时嵌入和对象标签不显示

发布于 2024-12-11 06:52:42 字数 1390 浏览 2 评论 0原文

我目前使用的是 Firefox 7.0.1。我一直在开发所见即所得编辑器,最近发现了在可编辑文档中嵌入内容的问题。我不确定这是否是一个错误,但是当文档具有 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";

对于此问题有任何解决方案或解决方法吗?

I'm currently using Firefox 7.0.1. I've been working on a WYSIWYG editor and just recently discovered an issue with embedding content in editable documents. I'm not sure if this is a bug, but when a document has designMode=on embeded content like:

<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>

... does not display at all in the page. If the design mode is toggled off the content displays just fine, but otherwise the object doesn't load and it's nearly impossible to edit around the content since you can't see where it is. I could build a placeholder, but I would much prefer having the content visible in the document that is being edited. This is the base document that I use within the iframe for editing pages:

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>';

Here is the code for generating the editable iframe doc:

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";

Is there any solution or workaround for this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜夜流光相皎洁 2024-12-18 06:52:42

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

I ended up solving this by parsing the embed, object, and param tags and placed the the data in an iframe before adding it to the document. This is an excellent solution for anyone using a transitional doctype.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文