自动识别网页文件类型

- 中国WEB开发者网络 (http://www.webasp.net)
-- 网页特效 (http://www.webasp.net/javascript/)
--- 自动识别网页文件类型 (http://www.webasp.net/javascript/1/442.htm)
-- 发布日期: 2005-06-10
<!-- 网页特效代码由[中国WEB开发者网络:http://www.ChinaWebDev.com]提供! -->
<!-- 要实现此效果需要 2 个步骤: -->

<!-- 第 1 步: -->
<!-- 把下面的代码加到<HEAD></HEAD>区域中: -->


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
URL = window.location.href;
ishtm = (URL.indexOf('.htm') > -1);
ishtml = (URL.indexOf('.html') > -1);
isshtml = (URL.indexOf('.shtml') > -1);
isphtml = (URL.indexOf('.phtml') > -1);
// End -->
</script>



<!-- 第 2 步: -->
<!-- 把下面的代码加到<BODY></BODY>区域中: -->

<center>
<SCRIPT LANGUAGE="JavaScript">
if (isphtml) {
document.write("这是一个 .phtml 文件!");
}
else if (isshtml) {
document.write("这是一个 .shtml 文件!");
}
else if (ishtml) {
document.write("这是一个 .html 文件!");
}
else if (ishtm) {

document.write("这是一个 .htm 文件!");
// Include the generic .htm last because if tested
// first, it would be true for all the file types above

}
else {
document.write("无法识别该类文件.");
}
</script>
</center>


webasp.net