我想在不打開它的情況下獲得網頁的標題,即不使用window.open()
。 我基本上想檢查頁面是否提供存在的鏈接或返回錯誤。如何使用JavaScript獲取鏈接的標題
我正在嘗試檢查類似的鏈接。這裏是代碼 (我想知道什麼時候跳出這個循環,也就是說我寫的鏈接在什麼時候存在)。
document.getElementById("TOI").innerHTML="<p>";
if (month<10) var m="0"+month;
else var m=month;
for(var i=1;;i++){
alert("ji");
var a="http://epaper.timesofindia.com/Repository/CAP/"+year+"/"+m+"/"+date+"/CAP_"+year+"_"+month+"_"+date+"_"+i+".pdf";
alert(a);
var link=window.open(a);
window.focus();
alert(link.location);
alert(link.document.title);
if(link.document.title!="The page cannot be found"){
link.close();
document.getElementById("TOI").innerHTML=document.getElementById("TOI").innerHTML+"<a href='http://epaper.timesofindia.com/Repository/CAP/"+year+"/"+m+"/"+date+"/CAP_"+year+"_"+month+"_"+date+"_"+i+".pdf' target=_blank>Page "+i+"</a> ";
}
else{link.close();break;}
}
document.getElementById("TOI").innerHTML=document.getElementById("TOI").innerHTML+"<\p>";
}
如果您想遵循此方法,我可能會發布一些代碼片段。 –
我該如何處理php [我想知道某個遠程服務器上的頁面狀態] –
好吧我使用的是php,但由於我要求大量文件,所以花費的時間太多。 這是我用的 '$ i = 59; ($; i> 0; $ i - ){ \t \t \t $ ideal =「HTTP/1.0 200 OK」; \t \t \t $ url ='http://epaper.timesofindia.com/Repository/ETD/'.date("Y").'/'.date("m").'/'.date("d 「) '/ ETD _' 日期(。」 Y「).'_ '日期( 」M「).'_' 日期( 」d「).'_ PDF '」 $我。'。 \t \t \t $ status = get_headers($ url); \t \t \t $ status = $ status ['0']; \t \t \t如果($狀態== $理想){ \t \t \t \t回聲$ I; \t \t \t \t break; \t \t \t} \t \t}' 任何其他選項??? –