I am trying to create a script that asks for a YouTube video link and following explodes it and automatically inserts it into the editor.
The trick is however not working.
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 );
}
It generates the following error :
Error: Syntax error, unrecognized expression: https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrPpO65UbM6Y
I already tried to add the following tags : encodeURIComponent()
But to no result
I tried to add escape() instead of encodeURIComponent Also no result.
Gave the following error :
Error: Syntax error, unrecognized expression: https%3A//www.youtube.com/watch%3Fv%3DrPpO65UbM6Y
Edit!
It works!! Thanks to @SearchAndResQ
The following code :
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 ); }