I came across this code somewhere in my travels and though I don't understand it fully, it looks like what you are after:
Code:
function getFile(filename)
{ oxmlhttp = null;
try
{ oxmlhttp = new XMLHttpRequest();
oxmlhttp.overrideMimeType("text/xml");
}
catch(e)
{ try
{ oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{ return null;
}
}
if(!oxmlhttp) return null;
try
{ oxmlhttp.open("GET",filename,false);
oxmlhttp.send(null);
}
catch(e)
{ return null;
}
return oxmlhttp.responseText;
}
It is actually meant to retrieve the contents of a file for use elsewhere in your code but, it will return null if the file isn't there. I think it will only work on the same domain as the page it is looking for but, according to you, that is all you need. The way to use it would be to put it in a script block in the head of your page and then just after it in the same script bock have:
Code:
if (getFile('index2.html')!==null)
window.location.replace('index2.html')
Put this all together and you've got:
Code:
<script type="text/javascript">
function getFile(filename)
{ oxmlhttp = null;
try
{ oxmlhttp = new XMLHttpRequest();
oxmlhttp.overrideMimeType("text/xml");
}
catch(e)
{ try
{ oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{ return null;
}
}
if(!oxmlhttp) return null;
try
{ oxmlhttp.open("GET",filename,false);
oxmlhttp.send(null);
}
catch(e)
{ return null;
}
return oxmlhttp.responseText;
}
if (getFile('index2.html')!==null)
window.location.replace('index2.html')
</script>
Bookmarks