JS判断浏览器是否为IE 以及屏幕分辨率
来源:互联网 发布:儿童图书软件 编辑:程序博客网 时间:2024/05/21 07:52
<script type="text/javascript"> var dstURL = "http://www.baidu.com"if(-[1,]){ //alert("this is not ie"); //window.location.href = "http://www.baidu.com"}else{ //alert("this is ie"); var width = window.screen.width; if(width>1024) { // alert("clientscreen bigger than 1024"); window.location.href = dstURL; } else { // alert("smaller than 1024"); }} </script>
浏览器版本判断
在JS中判断浏览器的类型,估计是每个编辑过页面的开发人员都遇到过的问题。在众多的浏览器产品中,IE、Firefox、Opera、Safari........众多品牌却标准不一,因此时常需要根据不同的浏览器,甚至相同浏览器不同版本做不同的操作,因此,知晓浏览器的判断方法,还是很重要的。下面列举一下常用的判断方法:
1、判断浏览器是否为IE
document.all ? 'IE' : 'others':在IE下document.all值为1,而其他浏览器下的值为0;
navigator.userAgent.indexOf("MSIE")>0 ? 'IE' : 'others':navigator.userAgent是描述用户代理信息。
navigator.appName.indexOf("Microsoft") != -1 ? 'IE' : 'others':navigator.appName描述浏览器名称信息。
2、判断IE版本
navigator.appVersion.match(/6./i)=="6." ? 'IE6' : 'other version':在已知是IE浏览器的情况下,可以通过此方法判断是否是IE6;
navigator.userAgent.indexOf("MSIE 6.0")>0 ? 'IE7' : 'other version':同上;
navigator.appVersion.match(/7./i)=="7." ? 'IE7' : 'other version':在已知是IE浏览器的情况下,可以通过此方法判断是否是IE7;
navigator.userAgent.indexOf("MSIE 7.0")>0 ? 'IE7' : 'other version':同上;
navigator.appVersion.match(/8./i)=="8." ? 'IE8' : 'other version':在已知是IE浏览器的情况下,可以通过此方法判断是否是IE8;
navigator.userAgent.indexOf("MSIE 8.0")>0 ? 'IE8' : 'other version':同上。
3、JS获取浏览器信息
浏览器代码名称:navigator.appCodeName
浏览器名称:navigator.appName
浏览器版本号:navigator.appVersion
对Java的支持:navigator.javaEnabled()
MIME类型(数组):navigator.mimeTypes
系统平台:navigator.platform
插件(数组):navigator.plugins
用户代理:navigator.userAgent
DEMO:
Js代码
<script language="JavaScript">
<!--
function getOs()
{
var OsObject = "";
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
return "Firefox";
}
if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
return "Safari";
}
if(isCamino=navigator.userAgent.indexOf("Camino")>0){
return "Camino";
}
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
return "Gecko";
}
}
alert("您的浏览器类型为:"+getOs());
-->
</script>
JS屏幕分辨率属性
网页可见区域宽:document.body.clientwidth 网页可见区域高:document.body.clientheight 网页可见区域宽:document.body.offsetwidth (包括边线和滚动条的宽) 网页可见区域高:document.body.offsetheight(包括边线的宽) 网页正文全文宽:document.body.scrollwidth 网页正文全文高:document.body.scrollheight 网页被卷去的高:document.body.scrolltop 网页被卷去的左:document.body.scrollleft 网页正文部分上:window.screentop 网页正文部分左:window.screenleft 屏幕分辨率的高:window.screen.height 屏幕分辨率的宽:window.screen.width 屏幕可用工作区高度:window.screen.availheight 屏幕可用工作区宽度:window.screen.availwidth 屏幕设置 window.screen.colordepth 位彩色 屏幕设置 window.screen.devicexdpi 像素/英寸本文原始链接:<a target=_blank href="http://www.jbxue.com/article/17848.html">http://www.jbxue.com/article/17848.html</a>
- JS判断浏览器是否为IE 以及屏幕分辨率
- js 简单判断是否为ie浏览器
- js判断是否为IE浏览器
- js判断是否为IE浏览器
- JS判断浏览器是否为IE
- js判断当前浏览器是否为ie
- js判断当前浏览器是否为IE
- js判断是否为IE浏览器
- js判断浏览器是否为ie
- JS判断是否为IE浏览器
- [js实例] js判断浏览器是否为ie
- 判断浏览器是否为IE
- 判断是否为IE浏览器
- js判断是否IE浏览器
- JS判断浏览器是否为IE的方式
- 最短的JS判断是否为IE浏览器
- 在 JS 中判断浏览器是否为 IE
- JS判断浏览器是否为IE(__proto__)
- 这些天学习hadoop的一些记录
- Auto Layout用法剖析(2)
- (二)memcached 安装和实践demo
- Git库对象
- flume学习(十一):如何使用Spooling Directory Source
- JS判断浏览器是否为IE 以及屏幕分辨率
- 基于web服务的文件共享平台pydio搭建教程
- nodejs上传功能实现
- IOS后台运行
- 多线程编程
- elasticsearch数据备份与还原恢复
- [挑战程序设计竞赛] POJ 2718 - Smallest Difference
- w3m 设置用户名密码自动登录
- UVa 12333 - Revenge of Fibonacci(字典树+高精度压位)