js 判断网页类型

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
<SCRIPT LANGUAGE="JavaScript">
    URL = window.location.href;            //获取网页当前URL地址
    ishtm = (URL.indexOf('.htm') > -1);    //判断地址中包含的字符串
    ishtml = (URL.indexOf('.html') > -1);
    isshtml = (URL.indexOf('.shtml') > -1);
    isphtml = (URL.indexOf('.phtml') > -1);
    isaspx = (URL.indexOf('.aspx') > -1);
</script>
</head>
<body>
<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 文件!"); 
else if (aspx) 
    document.write("这是一个.aspx文件!");
else { 
document.write("无法识别该类型文件.");
}
</script>
</body>
</html>
posted @ 2013-08-10 18:05  也许明天  阅读(377)  评论(1编辑  收藏  举报