我想在不打开网页的情况下获得网页的标题,也就是说,不使用window.open()。我基本上是想检查我为其提供链接的页面是否存在,或者返回了一个错误。
我正在尝试的是检查类似的链接。下面是代码(我想知道什么时候跳出这个循环,也就是说,我正在写的链接在什么地方存在)。
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>";
}发布于 2011-06-29 17:44:29
var attribute = element.getAttribute("title");https://stackoverflow.com/questions/6518625
复制相似问题