xssFilter導致插入視頻異常,編輯器在切換源碼的過程中過濾掉img的_url屬性(用來存儲視頻url)_src/plugins/video.js裏處理的是_url,而不是_src。
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)
後,再輸出到前端頁面。