通过浏览器判断显示什么页面

以下代码经本人在IE6、IE7、Firefox、Opera浏览器测试成功。它的功能是如果你的浏览器是中文版的IE7、Firefox、Opera则不管你输入的域名是中文还是英文都自动转跳到中文域名,如果是中文域名则自动去掉前面的 www.,如果你的浏览器为IE6或更低版本以及其它浏览器,则地址栏显示的是英文域名。
以下代码使用的域名为loongcom.com   hotbiz.cn  服务.cn   服务.中国,带www的和不带www的,请自己修改网址,把这段javascript程序放在首页default.html的<head> </head>区域即可

 

<script language="javascript" type="text/javascript"> 本程序为龙永超编写,可以随意修改。联系QQ:187029320 使用时请把你的网站空间首页文件默认设置为default.html,网站的真正首页文件为index.html
function support(){
var ua = navigator.userAgent; //通过解析navigator对象的userAgent属性来获得浏览器的完整版本号
var IE = ua.indexOf("MSIE "); // IE将自己标识为MSIE,后面带一个空格,版本号以及分号。所以我们只要取空格和分号之间的部分即可
var name = navigator.appName; //获取浏览器的名称
if (name == 'Netscape') //如果浏览器为Firefox
var l = navigator.language; //定义Firefox浏览器的默认语言
else
var l = navigator.browserLanguage;//定义非Firefox浏览器的默认语言
if((ua.indexOf("Win") != -1) && (IE >= 7) && (l.indexOf('zh') > -1))return true;//windows操作系统、浏览器版本大于7且浏览器默认语言为中文
if ((ua.indexOf("Win") != -1) && (name == "Netscape") && (l.indexOf('zh') > -1))return true;//windows操作系统、浏览器为Firefox且浏览器默认语言为中文
if ((ua.indexOf("Win") != -1) && (name == "Opera") && (l.indexOf('zh') > -1))return true;//windows操作系统、浏览器为Opera且浏览器默认语言为中文
  return false;
}

function chinaesedomain(){if(support()){
try {
if( self.location == "http://服务.cn/" ) { top.location.href = "http://服务.cn/index.html"; } //去掉中文域名前面的www.
else if( self.location == "http://www.xn--zfr188b.xn--fiqs8s/" ) { top.location.href = "http://服务.cn/index.html"; }//解决Firefox浏览器地址栏不显示纯中文域名的问题
else if( self.location == "http://xn--zfr188b.xn--fiqs8s/" ) { top.location.href = "http://服务.cn/index.html"; } //解决Firefox浏览器地址栏不显示纯中文域名
else if( self.location == "http://www.xn--zfr188b.cn/" ) { top.location.href = "http://hotbiz.cn/index.html"; }//解决IE6浏览器访问中文.cn域名地址栏显示转码的问题
else if( self.location == "http://xn--zfr188b.cn/" ) { top.location.href = "http://hotbiz.cn/index.html"; }  //解决IE6浏览器访问中文.cn域名地址栏显示转码的
else if( self.location == "http://www.服务.中国/" ) { top.location.href = "http://服务.中国/index.html"; }//去掉中文域名前面的www.
else if( self.location == "http://服务.中国/" ) { top.location.href = "http://服务.中国/index.html"; } //去掉中文域名前面的www.
else if( self.location == "http://www.服务.cn/" ) { top.location.href = "http://服务.cn/index.html"; }//去掉中文域名前面的www.
else { top.location.href = "http://服务.cn/index.html"; }//输入其它域名都自动转跳到中文域名
}
catch(e) { }

  }else{
  try {
if( self.location == "http://www.xn--zfr188b.cn/" ) { top.location.href = "http://hotbiz.cn/index.html"; }//解决IE6浏览器访问中文.cn域名地址栏显示转码的问题
else if( self.location == "http://xn--zfr188b.cn/" ) { top.location.href = "http://hotbiz.cn/index.html"; }  //解决IE6浏览器访问中文.cn域名地址栏显示转码的
else { top.location.href = "index.html"; } //非IE7浏览器为IE6或更低版本以及其它浏览器,则地址栏显示的英文域名不变
}
catch(e) { }
  }
}

chinaesedomain();
</script>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值