var url="https://sf1-ttcdn-tos.pstatp.com/obj/temai/9649f28160a4873b097fe23316c66280fa330f2fw55";
var url1="https://sf1-ttcdn-tos.pstatp.com/obj/temai/9649f28160a4873b097fe23316c66280fa330f2fwww800-800";
debugger;
// var result=CheckImgExists(url1).then(()=>{
// alert('true')
// }).catch(()=>{
// alert('false')
// });
// async function() {
// var result=await isHasImg(url);
// alert(result)
// }
var result=ishttppritrue(url1);
alert(result)
function ispritrue(){
var Img = new Image;
var ss=0;
Img.onload = function()
{
alert(url + " 存在。");
return true
}
Img.onerror = function()
{
alert(url + " 未找到,可能是网址错误,或不是一个图片文件。");
return false
}
Img.src = url;
}
function ispritrue2(){
var oReq = new ActiveXObject("Microsoft.xmlHTTP")
oReq.open("Get","UploadFiles/2007829144941621.gif",false);
oReq.send();
//alert(oReq.status)
if(oReq.status==404){
alert('不存在');
return false;
}
else{
alert("存在")
return true;
}
}
function CheckImgExists(imgurl) {
return new Promise(function(resolve, reject) {
var ImgObj = new Image(); //判断图片是否存在
ImgObj.src = imgurl;
ImgObj.onload = function(res) {
resolve(res);
}
ImgObj.onerror = function(err) {
reject(err)
}
})
}
function isHasImg( src ){
var img = new Image();
img.src = src;
img.onload = function(){
if( img.width > 0 || img.height > 0 ){
return true
}
else{
return false
}
}
img.onerror = function(){
return false
}
}
function onImgExistNotify(src,bExist,iPlace){//图片src是否存在通知
if( bExist ){
console.log("图片src="+src+"存在"+iPlace);
}
else{
console.log("图片src="+src+"不存在"+iPlace);
}
}
function ishttppritrue(src){
const xhr = new XMLHttpRequest();
debugger
xhr.open('GET', src, false); // 同步的XMLHttpRequest请求
xhr.send();
xhr.response.encoding = 'gbk';
debugger;
if(xhr.status=='404') {
return false;
}
else{
return true;
}
}
function gb2utf8(data){
var glbEncode = [];
gb2utf8_data = data;
execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
t=t.split("@");
var i=0,j=t.length,k;
while(++i<j) {
k=t[i].substring(0,4);
if(!glbEncode[k]) {
gb2utf8_char = eval("0x"+k);
execScript("gb2utf8_char = Chr(gb2utf8_char)", "VBScript");
glbEncode[k]=escape(gb2utf8_char).substring(1,6);
}
t[i]=glbEncode[k]+t[i].substring(4);
}
gb2utf8_data = gb2utf8_char = null;
return unescape(t.join("%"));
}
console