Skip to Content

getYoutubeTitle()

Get the title of the Youtube video (or use best fallback possible)

JavaScript July 2, 2019

Usage

JavaScript
nebula.getYoutubeTitle(target)

Parameters

target
(Required) (Object) The event target passed within the Youtube API functions
Default: None

Request or provide clarification »

Examples

JavaScript
function nebulaYoutubeError(e){
    thisVideo.title = nebula.getYoutubeTitle(e.target);
}

Additional Notes

This checks if the undocumented getVideoData() function is available from the Youtube API. Either way it tries to return the most applicable title available. The fallback stack is Youtube title, iframe title attribute, or video ID.

Source File

Located in /assets/js/nebula.js on line 4895.

JavaScript
nebula.getYoutubeTitle = function(target){
    var videoTitle;

    //If getVideoData is available in the API
    if ( target.getVideoData ){
        videoTitle = target.getVideoData().title;
    }

    return videoTitle || jQuery(target.getIframe()).attr('title') || nebula.getYoutubeID(target) || false;
};

Override

To override or disable this JavaScript function, simply redeclare it with the exact same function name.

JavaScript
nebula.getYoutubeTitle = function(target){
    //Write your own code here, leave it blank, or return false.
}