如果有人从页面或电子邮件中抓取了一些东西但没有捕获所有内容,然后将其粘贴到缺少标签(如 <p>
和 <div>
)的 TinyMCE 中,您如何防止那些未关闭的标签溢出到你页面的其余部分?谢谢!
最佳答案
考虑实现 Tiny MCE Paste plugin ,它有一个选项paste_auto_cleanup_on_paste
您可以设置为 true 以在粘贴任何 HTML 后对其进行整理。
来自链接示例:
tinyMCE.init({
theme : "advanced",
mode : "textareas",
plugins : "paste",
theme_advanced_buttons3_add : "pastetext,pasteword,selectall",
paste_auto_cleanup_on_paste : true,
paste_preprocess : function(pl, o) {
// Content string containing the HTML from the clipboard
alert(o.content);
o.content = "-: CLEANED :-\n" + o.content;
},
paste_postprocess : function(pl, o) {
// Content DOM node containing the DOM structure of the clipboard
alert(o.node.innerHTML);
o.node.innerHTML = o.node.innerHTML + "\n-: CLEANED :-";
}
});
关于javascript - TInyMCE - 防止粘贴损坏的 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7154192/