第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JQ怎么跨域判斷HTTPS的URL資源是否有效?

JQ怎么跨域判斷HTTPS的URL資源是否有效?

qq_笑_17 2019-05-22 23:01:50
有一個需求是這這樣的,當(dāng)頁面加載完的時候,根據(jù)當(dāng)前頁面的URL,來判斷對應(yīng)的圖片資源是否存在,如果存在則就用這個對應(yīng)的圖片,如果不存在則使用默認(rèn)的圖片。假設(shè)當(dāng)前頁面URL:https://www.example.com/somep...規(guī)則對應(yīng)的圖片文件是someid.png,圖片的URL:https://imgs.example.com/imgs...如果不存在這張圖片,則使用默認(rèn)的https://imgs.example.com/imgs...這里的jquery如何去判斷https://imgs.example.com/imgs...?varpopup=(function(){vartarget=window.location.href;varcurrentFilename=window.location.pathname.split("/")[window.location.pathname.split("/").length-1].split(".")[0];varcurrentPopupImg='https://imgs.example.com/'+currentFilename+'.png';vardefautlPopupImg='https://imgs.example.com/default.png';varpicContent="";varcheckPopupImgOnce=function(){$.ajax({url:currentPopupImg,cache:false,dataType:"jsonp",type:'GET',complete:function(response){if(response.status==200){picContent=currentFilename;}else{changePopUpImgSrc();}}});}varchangePopUpImgSrc=function(){picContent=defautlPopupImg;}varshowPopUp=function(){varflag=0;layer.open({type:1,title:false,closeBtn:0,shade:0,shadeClose:true,anim:0,skin:'popup',area:['600px','450px'],time:12000,resize:false,btn:['不再提醒','稍后再說','立即了解'],yes:function(index,layero){//按鈕【按鈕一】的回調(diào)//永遠(yuǎn)關(guān)閉彈窗flag=1;layer.closeAll();},btn2:function(index,layero){//按鈕【按鈕二】的回調(diào)//$("#layui-layer1").hide();//暫時關(guān)閉彈窗flag=0;layer.close(index);},btn3:function(index,layero){//按鈕【按鈕三】的回調(diào)//returnfalse開啟該代碼可禁止點擊該按鈕關(guān)閉//打開快商通//暫時關(guān)閉彈窗flag=0;window.open('https://ad.example.com');layer.close(index);},btnAlign:'c',content:picContent,end:function(){if(flag==1){//永遠(yuǎn)關(guān)閉彈窗window.clearTimeout(timer);}else{timer=setTimeout(popup,15000);}}});}varpop={checkimg:checkPopupImgOnce,showPopUp:showPopUp}returnpop;})();popup.checkimg();popup.showPopUp();
查看完整描述

2 回答

?
喵喔喔

TA貢獻1735條經(jīng)驗 獲得超5個贊

利用標(biāo)簽,大致思路:
functionisValidImage(url,successCallback,abortCallback,errorCallback){
varimg=document.createElement('img');
img.src=url
img.onload=successCallback
img.onabort=abortCallback
img.onerror=errorCallback
returnimg
}
                            
查看完整回答
反對 回復(fù) 2019-05-22
  • 2 回答
  • 0 關(guān)注
  • 641 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號