標籤: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) {//IEreturn "IE";} else if (u.indexOf('Presto') > -1) {//operareturn "Opera";} else if (u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1) {//firefoxreturn "Firefox";} else if (u.indexOf('AppleWebKit' && u.indexOf('Safari') > -1) > -1) {//蘋果、Google核心if (u.indexOf('Chrome') > -1) {//chromereturn "Chrome";} else if (u.indexOf('OPR')) {//webkit Operareturn "Opera_webkit"} else {//Safarireturn "Safari";}} else if (u.indexOf('Mobile') > -1) {//移動端if (!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {//iosif (u.indexOf('iPhone') > -1) {//iphonereturn "iPhone"} else if (u.indexOf('iPod') > -1) {//ipodreturn "iPod"} else if (u.indexOf('iPad') > -1) {//ipadreturn "iPad"}} else if (u.indexOf('Android') > -1|| u.indexOf('Linux') > -1) {//androidnum = 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 phonereturn "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;//來源地址urlvar 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;}//當前頁面來源urlreferer = referer.replace('http://', '');}
我的個人部落格:http://blog.caicongyang.com ;
我的個人網站:http://www.caicongyang.com ;
我的CSDN部落格地址: http://blog.csdn.net/caicongyang ;
js擷取瀏覽器資訊和頁面資訊