php – javascript html编辑器复制/粘贴问题

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – javascript html编辑器复制/粘贴问题脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我们运行一些大型目录,用户经常将word文档中的内容复制/粘贴到我们的TinyMCE html编辑器中.

这个问题通常是以下文本隐藏在那里,显示在我们的网页上:

<!-- /* Style DeFinitions */ p.MsoNormal,li.MsoNormal,div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; mso-layout-grid-align:none; punctuation-wrap:simple; text-autospace:none; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} a:link,span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited,span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} p {mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} -->

是否有TinyMCE插件或其他一些跨浏览器的html编辑器会自动删除它?

或者另一个解决方案是一些PHP regex命令或者可以删除这些注释声明的东西.

解决方法

多年来我一直在努力优化那个.

到目前为止,我最好的解决方案是:

>不使用根块,布局将实现根布局
>不要指望用户理解< p>之间的区别和< br />因此,将所有内容视为一个简单的中断,因为它不那么令人困惑,而且更像ms-word
>仅允许预期的元素

这将是init代码.

remove_linebreaks : false,force_br_newlines : true,<?PHP /* maybe we can behave more like gmail */ ?>
force_p_newlines : false,<?PHP /* and preserve all message line breaks */ ?> 
convert_newlines_to_brs : false,<?PHP /* even so i would not count with it */ ?>
forced_root_block : false

<?PHP /* explicitly define what will be allowed */ ?>
valid_elements: "h1,h2,h3,br,b,a,i,u,strong/b,em/i,u/span,strike/span,span,span[style],"+
                "sub,sup,a[href|name|anchor|target|title],ul,ol,li,p,object[classid|width|height|codebase|*],"+
                "param[name|value|_value],embed[type|width|height|src|*],"+
                "img[style|longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align]",

然后我有以下后处理功能删除所有< p>并转换所有< / p>到< br />< br />这是我能够开发的最稳定的复制粘贴解决方案.

这是后处理功能

setup : function(ed) {
    ed.onPostProcess.add(function(ed,o) {
        // Remove all paragraphs and replace with BR
        o.content = o.content.replace(/<p [^>]+>|<p>/g,'');
        o.content = o.content.replace(/<\/p>/g,'<br />');
    });
},

请注意,所有这些只是Javascript过滤,用户将能够快速将所有不需要的代码传递给服务器.即使这个设置可能用于最终管理员设置,也可以在服务器端使用strip_tags,因为某个人可能会绕过它.

希望能帮助到你!

脚本宝典总结

以上是脚本宝典为你收集整理的php – javascript html编辑器复制/粘贴问题全部内容,希望文章能够帮你解决php – javascript html编辑器复制/粘贴问题所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: