在html网站上嵌入视频链接检查器脚本

时间:2014-06-24 14:53:03

标签: javascript

我一直在寻找一个编写脚本的解决方案,该脚本会警告网站上的嵌入视频是否已在Youtube,Vimeo等视频提供商网站上删除或删除。

我到处寻找,但我找不到任何解决方案。

1 个答案:

答案 0 :(得分:0)

检查出来:

function isURLReal(fullyQualifiedURL) {
    var URL = encodeURIComponent(fullyQualifiedURL),
        dfd = $.Deferred(),
        checkURLPromise = $.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22' + URL + '%22&format=json');

    checkURLPromise
            .done(function(response) {
                // results should be null if the page 404s or the domain doesn't work
                if (response.query.results) { 
                    dfd.resolve(true);
                } else {
                    dfd.reject(false);
                }
            })
            .fail(function() {
                dfd.reject('failed');
            });
    });

    return dfd.promise();
}

// usage
isURLReal('http://google.com')
        .done(function(result) {
            // yes
        })
        .fail(function(result) {
            // no, or request failed
        });

此处详细信息:StackOverFlowLink