Jump to content

Checking the existence of a document


Recommended Posts

Is there a way to check if an html document exists?

I know that it can be done for a IMG tag with an onerror way and I tried to do it with an IFRAME tag with a onerror way but didin't work out.

Maybe a simple dos batch command of IF EXIST something like that would be nice but the script is only for client-side and thus needs to use only javascript and phps.

Link to comment
Share on other sites


var xmlhttp;

function loadXMLDoc(url) {
/* Mozilla */
if (window.XMLHttpRequest) {
 xmlhttp=new XMLHttpRequest();
 xmlhttp.onreadystatechange=state_Change
 xmlhttp.open("HEAD",url,true);
 xmlhttp.send(null);
} else
/* IE */
if (window.ActiveXObject) {
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 if (xmlhttp) {
 xmlhttp.onreadystatechange=state_Change
 xmlhttp.open("HEAD",url,true);
 xmlhttp.send();
 }
}
}

function state_Change() {
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4) {
 if (xmlhttp.status==200) {
 document.location.href="toc.html";
 // document.getElementById('T1').innerHTML=xmlhttp.getAllResponseHeaders()
 } else {
 // document.location.href="toc.html";
 }
}
}
loadXMLDoc('toc.html');

Thanx for suggestions ppl!

But I found out the way by using javascript XML or whatever its called when I searched for many hours!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...