引用:https://my.oschina.net/u/379795/blog/787985
xssFilter導致插入視頻異常,編輯器在切換源碼的過程中過濾掉img的_url屬性(用來存儲視頻url)_src/plugins/video.js里處理的是_url,而不是_src。<基本出處參見:https://github.com/fex-team/ueditor/pull/2957/commits/d4b875ce165b3225929496c2d85848afbff0deeb?diff=split >
1、在配置文件ueditor.config.js中,定位 //xss過濾白名單,即,whitList:{ },對 img: 增加 “_url” 屬性:
2、在下面的 video 標簽后面新增3給標簽,使Ueditor分別能支持embed標簽和iframe標簽:
代碼:
source: ['src', 'type'],
embed: ['type', 'class', 'pluginspage', 'src', 'width', 'height', 'align', 'style', 'wmode', 'play',
+ 'autoplay','loop', 'menu', 'allowscriptaccess', 'allowfullscreen', 'controls', 'preload'],
iframe: ['src', 'class', 'height', 'width', 'max-width', 'max-height', 'align', 'frameborder', 'allowfullscreen']
其中【】中的各個字段為前面相應標簽的屬性 比如:<iframe src="", width="", height=""></iframe>。
這樣,在編輯器中就可以引用優酷、騰訊視頻的iframe通用代碼和embed html代碼;移動端一般引用iframe,可設置屬性,使其適應設備。(這里,建議切換到源碼模式,插入相應的視頻代碼embed或iframe。其中iframe可編輯大小,優酷embed有效,騰訊embed無效;且騰訊視頻的iframe可設置為自動播放,優選)
注意:通過以上兩步后,可能出現的新問題是,前端頁面不解析<iframe>標簽,而是將其原樣輸出:
解決方法:用html_entity_decode()函數把HTML實體轉換為字符,該函數為php函數。
假設$string為從數據庫中取出的編輯器存入的內容:經html_entity_decode($string)后,再輸出到前端頁面。