我發現關於如何檢測圖像路徑是否有效?
How to detect if the image path is broken?
我曾嘗試以下代碼
var image = new Image;
image.src = "http://project" + path + '.png';
image.onload = function(){
var imageWidth = this.width + this.height;
if(imageWidth==0){
image.src = "http://project2" + path + '.png';
//the project2 path could be broken too and
//I want to use project3 or project4 as the
//path and keep testing it, but there is no way to do it from here.
}
}
有沒有可能在這裏做一個recursive
測試圖像的問題嗎?非常感謝!
簡單地打開開發人員工具並查看您的任何鏈接是否損壞是不夠的? – blackhawk 2013-05-02 17:54:04
我需要在飛行中做到這一點。所以代碼可以選擇具有有效路徑的圖像。 – FlyingCat 2013-05-02 17:54:31