Help - Search - Members - Calendar
Full Version: Checking the existence of a document
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
Vel Straty
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.
agraddy
Why not use the PHP is_file('my_page.html') function?

You can find more information at PHP.net
__________________
My Company: Setigo
My Work In Progress: Stillwater Oklahoma Rental
Stalkie
I would have suggested file_exists, but since it's only for files, the is_file should suffice.
Vel Straty
CODE
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!
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.