img = new Image();
img.crossOrigin = "anonymous";
try {
cimg.src = document.getElementById("url").value;
}
catch(err) {
alert("Cannot access image.Cross-Domain access blocked");
};
Run Code Online (Sandbox Code Playgroud)
所以,我想检测/捕获跨域访问阻止错误.
经过一番思考后我发现它的src加载是异步的,因此catch块不会工作.有没有办法检测错误,所以我可以有效地处理它?