I have a function that will create a new Youtube iframe for each JSON object.
var createYTPlayer = function () {
var ytVidPlayer = $("<iframe/>");
var videoId = raw_content.media[counter].video;
ytVidPlayer.attr({
height: 315,
width: 560,
src: 'https://www.youtube.com/embed/' + videoId,
frameborder: 0
});
return ytVidPlayer;
};
The video
function gets the returned YT player object from createYTPlayer
function.
var video = function () {
// Development
console.log('shortcodeController.video');
var outputHTML;
var ytPlayer;
if (raw_content.media[counter].video != undefined) {
outputHTML = '<div class="video">';
// Youtube object
ytPlayer = createYTPlayer();
console.log('youtube player: ', ytPlayer);
outputHTML += ytPlayer;
outputHTML +='</div>';
console.log(outputHTML);
return outputHTML;
};
};
Then it should covert the object to a string, because I receive the error in my string as [object Object]
. And I will add it to a JSON object that contains text. It will replace then a specific character from the JSON text with the output of the function video
, that returns the new video object.
How can I solve this?