現(xiàn)在的瀏覽器很多不再支持embed標(biāo)簽了,如何把kindeditor 中的 embed 換成 video
解決過程
步驟1、修改function _mediaType(){}
修改前
function _mediaType(src) { if (/\.(rm|rmvb)(\?|$)/i.test(src)) { return 'audio/x-pn-realaudio-plugin'; } if (/\.(swf|flv)(\?|$)/i.test(src)) { return 'application/x-shockwave-flash'; } return 'video/x-ms-asf-plugin'; }
修改后
function _mediaType(src) { if (/\.(rm|rmvb)(\?|$)/i.test(src)) { return 'audio/x-pn-realaudio-plugin'; } if (/\.(swf|flv)(\?|$)/i.test(src)) { return 'application/x-shockwave-flash'; } if (/\.(mp4)(\?|$)/i.test(src)) { return 'video/mp4'; } if (/\.(ogg)(\?|$)/i.test(src)) { return 'video/ogg'; } if (/\.(webm)(\?|$)/i.test(src)) { return 'video/webm'; } return 'video/x-ms-asf-plugin'; }
步驟2、修改 function _mediaEmbed(){}
修改前
function _mediaEmbed(attrs) { var html = '<embed '; _each(attrs, function(key, val) { html += key + '="' + val + '" '; }); html += '/>'; return html; }
修改后
function _mediaEmbed(attrs) { var html = '<p style="text-align:center;"><video '+ ' class="' + _mediaClass(attrs.type) + '" type="video/mp4" '; _each(attrs, function (key, val) { html += key + '="' + val + '" '; }); html += ' controls="controls" autoplay="autoplay" muted="muted" controlslist="nodownload" /></p>'; return html; }
步驟3、找到 function _mediaImg(){},添加mp4 判斷
if (attrs.src.indexOf(".mp4") != -1) { var html = `<p style="text-align:center;"><video src="${attrs.src}" controls="controls" width="${width}" height="${height}" class="${_mediaClass(attrs.type)}" type="video/mp4" >您的瀏覽器太老了, 不支持視頻播放。請下載最新瀏覽器!</video></p>` } else { var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" '; if (style !== '') { html += 'style="' + style + '" '; } html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />'; }
步驟4、添加 htmlTags 防止 video標(biāo)簽過濾掉
找到變量HtmlTags,添加以下代碼,請查看效果圖。
文章來源:http://www.zghlxwxcb.cn/article/508.html
video : ['autoplay','controls','height','loop','poster','src','width'],
文章來源地址http://www.zghlxwxcb.cn/article/508.html
到此這篇關(guān)于如何把kindeditor編輯器中的視頻格式embed改成video的文章就介紹到這了,更多相關(guān)內(nèi)容可以在右上角搜索或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!