How can I set up TinyMCE so that it won't allow inline data images?

点点圈 提交于 2019-12-10 04:22:47

问题


I have a TinyMCE installation on a CMS and the users have been pasting in images which are of the inline data type. This kind of thing:

<img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/
/ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcpp
V0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7" 
width="16" height="14" alt="embedded folder icon">

They are pasting in some pretty large images, and the content gets stored in a database. This is making the database grow very quickly in size, and there is already a media upload component available, so how can I simply prevent the editor from accepting this type of image?


回答1:


This depends on what you want. Due to the fact that you won't be able to disallow this kind of element using valid_elements and child_elements you will have to go other ways.

Case 1: You do not want user to enter this kind of image onPaste.

You will need to use the paste plugin and set the parameter paste_pre

paste_preprocess : function(pl, o) {
    window.console && console.log('Object', o);
    window.console && console.log('Content:', o.content);

    // modify o.content here -> remove images of that kind
    o.content = o.content.substr(...)
}

Case 2: You want the images to be filtered out before they are getting saved into the DB.

You may use the tinymce setup paramter combined with onSave to get rid of them.

From what you describe you seem to be wanting Case 1.



来源:https://stackoverflow.com/questions/7573474/how-can-i-set-up-tinymce-so-that-it-wont-allow-inline-data-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!