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 @   也许明天  阅读(386)  评论(1编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
点击右上角即可分享
微信分享提示