码迷,mamicode.com
首页 > Web开发 > 详细

js获取浏览器信息和页面信息

时间:2015-01-06 13:50:38      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:js获取浏览器信息   js获取页面信息   

1.js获取浏览器信息:包含判断是否为移动端,以及浏览器信息,android版本

2.js获取页面url、domain、title

	function browserInfo() {
		var browser = {
			versions : function() {
				var u = window.navigator.userAgent;
				//android版本
				var num;
				if (u.indexOf('Trident') > -1) {
					//IE
					return "IE";
				} else if (u.indexOf('Presto') > -1) {
					//opera
					return "Opera";
				} else if (u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1) {
					//firefox
					return "Firefox";
				} else if (u.indexOf('AppleWebKit' && u.indexOf('Safari') > -1) > -1) {
					//苹果、谷歌内核
					if (u.indexOf('Chrome') > -1) {
						//chrome	
						return "Chrome";
					} else if (u.indexOf('OPR')) {
						//webkit Opera
						return "Opera_webkit"
					} else {
						//Safari
						return "Safari";
					}
				} else if (u.indexOf('Mobile') > -1) {
					//移动端
					if (!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
						//ios
						if (u.indexOf('iPhone') > -1) {
							//iphone
							return "iPhone"
						} else if (u.indexOf('iPod') > -1) {
							//ipod	
							return "iPod"
						} else if (u.indexOf('iPad') > -1) {
							//ipad
							return "iPad"
						}
					} else if (u.indexOf('Android') > -1
							|| u.indexOf('Linux') > -1) {
						//android
						num = u.substr(u.indexOf('Android') + 8, 3);
						return {
							"type" : "Android",
							"version" : num
						};
					} else if (u.indexOf('BB10') > -1) {
						//黑莓bb10系统
						return "BB10";
					} else if (u.indexOf('IEMobile')) {
						//windows phone
						return "Windows Phone"
					}
				}
			}
		}
		//浏览器版本
		var browserVsersion = browser.versions();
		//当前页面路径
		var url = window.location.href;
		//当前页域名
		var host = window.location.host;
		//当前页域名
		var host2=document.domain; 
		
		alert(host2);
		//当前页面标题
		var title = document.title;
		//来源地址url
		var referer;
		if (document.referrer.length > 0) {
			referer = document.referrer;
		}
		try {
			if (referer.length == 0 && opener.location.href.length > 0) {
				referer = opener.location.href;
			}
		} catch (e) {
			referer = window.location.href;
		}
		//当前页面来源url
		referer = referer.replace('http://', '');
	
	}


我的个人博客:http://blog.caicongyang.com ;

我的个人网站:http://www.caicongyang.com ;

我的CSDN博客地址: http://blog.csdn.net/caicongyang ;





js获取浏览器信息和页面信息

标签:js获取浏览器信息   js获取页面信息   

原文地址:http://blog.csdn.net/caicongyang/article/details/42457827

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!