Detecting if YouTube is blocked by company / ISP

前端 未结 5 2031
心在旅途
心在旅途 2020-12-05 19:27

We have YouTube videos on a site and want to detect if it is likely that they will not be able to view them due to (mostly likely) company policy or otherwise.

We ha

5条回答
  •  粉色の甜心
    2020-12-05 19:56

    I like lacker's solution, but yes, it creates a race condition. This will work and won't create a race contition:

    var image = new Image();
    image.onload = function(){
    // The user can access youtube
    };
    image.onerror = function(){
    // The user can't access youtube
    };
    image.src = "http://youtube.com/favicon.ico";
    

提交回复
热议问题