I'm using the following code to set background-image thumbnails as placeholders for embedded youtube videos. If the video is removed the thumbnail becomes youtube's default 404 thumbnail. I'd like to set my own 404 thumbnail, but I'm not sure how. I can find ways to check for img errors but not for background-image errors. (Also, I can't look for divs with no background-image because they will all have one, it just might be a broken link.)
Anyone know how to check for a broken background-image url?
$(function(){
// VIDEO LOAD
var videoLinks = {};
function clickVideo() {
// trim off img-
var postId = $(this).attr("id").substr(4);
if (videoLinks[postId]) {
$("#" + postId).html(videoLinks[postId]);
}
}
function storeVideo() {
var videoDiv = this;
var postId = $(videoDiv).attr("id");
var code = $(videoDiv).attr("videohtml");
$(videoDiv).removeClass("videoNoThumbnail");
var re = new RegExp("(.*/embed/([a-zA-Z0-9_-]+)\\?)(.*)", "m");
var match = code.match(re);
if (match) {
code = match[1] + "autoplay=1&" + match[3];
var videoId = match[2];
var div = $("<div class=videoThumbnail />");
div.css("background-image",
"url('http://img.youtube.com/vi/" + videoId + "/0.jpg')");
var img = $("<img src=http://dinakelberman.com/play.png class=playButton />");
img.attr("id", "img-" + postId);
img.click(clickVideo);
div.append(img);
// two.empty();
$(videoDiv).append(div);
}
videoLinks[postId] = code;
}
function updateVideos() {
$('div.videoNoThumbnail').each(storeVideo);
setTimeout(updateVideos, 200);
}
updateVideos();
})