【发布时间】:2015-10-05 09:37:01
【问题描述】:
我正在尝试创建一个脚本,要求提供 YouTube 视频链接,然后将其分解并自动将其插入到编辑器中。
但是这个技巧不起作用。
function TinyMCEInsertYouTube() {
var YouTubeLink = encodeURIComponent(prompt("Please insert the YouTube link"));
var result = $(YouTubeLink).text().split('watch?v=');
var VideoIDParam = result[1];
var VideoHeight = prompt("Please enter the video height");
var VideoWidth = prompt("Please enter the video width");
var InsertCode = '<iframe width="' + VideoWidth + '" height="' + VideoHeight + '" src="https://www.youtube.com/embed/' + VideoIDParam + '" frameborder="0" allowfullscreen></iframe>'
tinyMCE.activeEditor.insertContent( InsertCode );
}
它会产生以下错误:
错误:语法错误,无法识别的表达式:https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrPpO65UbM6Y
我已经尝试添加以下标签: encodeURIComponent()
但没有结果
我尝试添加 escape() 而不是 encodeURIComponent 也没有结果。
出现以下错误:
错误:语法错误,无法识别的表达式:https%3A//www.youtube.com/watch%3Fv%3DrPpO65UbM6Y
编辑!
有效!!感谢 @SearchAndResQ
以下代码:
function TinyMCEInsertYouTube() { var YouTubeLink = prompt("Please insert the YouTube link"); var result = YouTubeLink.split('watch?v='); var VideoIDParam = result[1]; var VideoHeight = prompt("Please enter the video height"); var VideoWidth = prompt("Please enter the video width"); var InsertCode = '<iframe width="' + VideoWidth + '" height="' + VideoHeight + '" src="https://www.youtube.com/embed/' + VideoIDParam + '" frameborder="0" allowfullscreen></iframe>' tinyMCE.activeEditor.insertContent( InsertCode ); }
【问题讨论】: