完全重新加载 TinyMCE
我编写 CMS 已经有一段时间了,目前正在对其进行最后的一些修改。其中之一包括使用 ajax 在灯箱样式的窗口中提供tinyMCE 编辑器。
当它加载时,第一次它工作得很好,但是当我第二次或更多次加载时,元素名称会变得混乱,并且它不会发回数据,也不会在 TinyMCE 窗口中显示当前值。当我使用 Chrome 检查该元素时,我可以看到包含之前的 tinyMCE 窗口的跨度仍然存在。
我使用 document.body.removeChild 来删除持有它的 div。有人有什么想法吗?
添加:
当 AJAX 从发出请求返回时(它具有窗口中的所有 html 代码),它会创建一个新的 div 元素并使用 document.body.appendChild 将元素添加到文档并将 html 代码放入 div 标签中。
然后它遍历新代码并搜索该区域中的脚本(其中一个是 MCE 启动器)并将它们附加到头部以便执行它们。
如果用户单击“取消”而不是“保存”,则会使用以下方法删除 div 标签: document.body.removeChild(document.getElementById("popupbox")); 效果很好,
但是当我像前面所说的那样弹出并重新填充,并检查那里的元素时,那里仍然有一个由 TinyMCE 创建的跨度,并且命名已更改(而不是由“内容”标识,它由于某种原因现在是 8)并且编辑器区域中没有内容。
我用过: tinyMCE.execCommand('mceRemoveControl',true,'mce{$Setting['name']}'); tinyMCE.editors[0].destroy();
但它们都不起作用。他们将 tinymce 窗口返回到文本区域,但元素仍然存在。
I have been writing a CMS for a while now and am currently putting the last few touches on it. one of which includes using ajax to deliver a tinyMCE editor in a lightbox styled window.
when it is loaded, the first time it works perfectly, but when i do it the second time or more, the element names get messed up and it doesn't send data back, or display the current value in the TinyMCE window. When I use Chrome to inspect the element, I can see that the span that contains the previous tinyMCE window is still there.
I use document.body.removeChild to remove the div that is holding it. Does anyone have any ideas?
Addition:
when AJAX gets back from making the request (it has all the html code of what goes in the window), it creates a new div element and uses document.body.appendChild to add the element to the document and puts the html code into the div tag.
Then it travels through the new code and searches for the scripts in that area (of which one is the MCE initiator) and appends them to the head so they are executed.
if the user clicks cancel rather than save, it removes the div tag by using:
document.body.removeChild(document.getElementById("popupbox"));
which works fine,
however when i bring up popup and repopulate as said before, and inspect the elements there, there is still a span there which was created by TinyMCE and the naming has been changed (instead of being identified by 'content', it is now 8 for some reason) and there is no content in the editor region.
I have used:
tinyMCE.execCommand('mceRemoveControl',true,'mce{$Setting['name']}');
tinyMCE.editors[0].destroy();
but neither of them work. They return the tinymce window to a textarea, but the elements are still there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在移动或删除包含tinymce iframe的html元素之前,按照您所描述的方式删除编辑器(使用正确的tinymce编辑器id)是一个不错的选择。你在哪里加载tinymce.js?如果您使用 ajax 传递它,我认为最好将其加载到父页面上(!)。更多代码会有所帮助。
编辑:我记得有一次我必须删除剩余的跨度的情况。这是我的代码:
Removing the editor as you described (using the correct tinymce editor id) before moving or removing the html element holding the tinymce iframe is a good choice. Where do you load your tinymce.js? If you deliver it using ajax i think it might be better to load it on the parent page(!). Some more code would be helpfull.
EDIT: I remember a situation where i had to remove a leftover span. Here is my code for this: