/** 獲取瀏覽器的userAgent */html
function getUserAgent(){linux
return navigator.userAgent;android
}ios
/** 獲取終端的語言 */chrome
function getClientLanguage(){windows
var type=navigator.appName;瀏覽器
var client_language = "";app
if (type=="Netscape"){ iphone
client_language = navigator.language;spa
}
else{
client_language = navigator.userLanguage;
}
return client_language;
}
/** 獲取瀏覽器類型 */
function getBrowerType(){
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
if(Sys.ie){
if(Sys.ie > 6.0){
return "IE "+Sys.ie;
}
}else if(Sys.firefox){
return "Firefox "+Sys.firefox;
}else if(Sys.chrome){
return "Chrome "+Sys.chrome;
}else if(Sys.opera){
return "Opera "+Sys.opera;
}else if(Sys.safari){
return "Safari "+Sys.safari;
}else if(ua.indexOf("uc") > -1){
return "UC";
}else{
return "Unknown";
}
}
/** 獲取瀏覽器語言 */
function getBrowerLanguage(){
var language = window.navigator.language;
if(!language){
language = window.navigator.browserLanguage;
}
language = language.toLowerCase();
return language;
}
/** 獲取客戶端操做系統類型 ,這個比較全面*/
function TClientCheck_OS() {
var sUA = navigator.userAgent.toLowerCase();//獲取瀏覽器用戶代理
var isIPhone = sUA.indexOf("iphone") > -1;
var isAndroid = sUA.indexOf("android")>-1 || sUA.indexOf("linux")>-1;
var isIPod = sUA.indexOf("ipod") > -1;
var isIPad = sUA.indexOf("ipad")> -1;
var isWP = sUA.indexOf("windows phone") > -1 ;
var isSymbian = sUA.indexOf( "symbian")> -1;
var isWin = sUA.indexOf( "win" ) > -1 ;
var isLinux = (sUA.indexOf("linux")> -1);
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
var isUnix = (navigator.platform == "X11"&&sUA.indexOf("unix"));
if(isAndroid){return "Android";}
if(isLinux) {return "Linux";}
if(isIPod){return "iPod";}
if(isIPad){return "iPad";}
if(isIPhone){return "iPhone";}
if(isWP){return "Windows Phone";}
if(isSymbian) {return "Symbian";}
if(isWin && !isWP){
var isWin2K = sUA.indexOf("windows nt 5.0") > -1 || sUA.indexOf("windows 2000") > -1;
if (isWin2K) return "Win 2000";
var isWinXP = sUA.indexOf("windows nt 5.1") > -1 || sUA.indexOf("windows xp") > -1;
if (isWinXP) return "Win XP";
var isWin2003 = sUA.indexOf("windows nt 5.2") > -1 || sUA.indexOf("windows 2003") > -1;
if (isWin2003) return "Win 2003";
var isWinVista = sUA.indexOf("windows nt 6.0") > -1 || sUA.indexOf("windows vista") > -1;
if (isWinVista) return "Win Vista";
var isWin7 = sUA.indexOf("windows nt 6.1") > -1 || sUA.indexOf("windows 7") > -1;
if (isWin7) return "Win 7";
var isWin8 = sUA.indexOf("windows nt 6.2") > -1 || sUA.indexOf("windows 8") > -1;
if (isWin8) return "Win 8";
return "Windows";
}
if(isUnix && !isWin && !isMac) {return "Unix";}
if(isMac &&!isIPod && !isIPad && !isIPhone) {return "Mac";}
return "Unknown";
}
/** 獲取屏幕的分辨率及其餘相關參數 */
function getScreen()
{
var s = "";
s += " 網頁可見區域寬:" + document.body.clientWidth + "\n";
s += " 網頁可見區域高:" + document.body.clientHeight + "\n";
s += " 網頁可見區域寬:" + document.body.offsetWidth + " (包括邊線和滾動條的寬)" + "\n";
s += " 網頁可見區域高:" + document.body.offsetHeight + " (包括邊線的寬)" + "\n";
s += " 網頁正文全文寬:" + document.body.scrollWidth + "\n";
s += " 網頁正文全文高:" + document.body.scrollHeight + "\n";
s += " 網頁被捲去的高(ff):" + document.body.scrollTop + "\n";
s += " 網頁被捲去的高(ie):" + document.documentElement.scrollTop + "\n";
s += " 網頁被捲去的左:" + document.body.scrollLeft + "\n";
s += " 網頁正文部分上:" + window.screenTop + "\n";
s += " 網頁正文部分左:" + window.screenLeft + "\n";
s += " 屏幕分辨率的高:" + window.screen.height + "\n";
s += " 屏幕分辨率的寬:" + window.screen.width + "\n";
s += " 屏幕可用工做區高度:" + window.screen.availHeight + "\n";
s += " 屏幕可用工做區寬度:" + window.screen.availWidth + "\n";
s += " 你的屏幕設置是 " + window.screen.colorDepth + " 位彩色" + "\n";
s += " 你的屏幕設置 " + window.screen.deviceXDPI + " 像素/英寸" + "\n";
return s;
}
/** 獲取屏幕分辨率 */
function getScreenDPI(){
os_type = TClientCheck_OS();//操做系統類型
if(os_type=="iphone")
{
return (window.screen.width*2) +"*"+(window.screen.height*2);
}
return window.screen.width +"*"+window.screen.height;
}
//終端類型
function getClientModel( ){
var sUA = navigator.userAgent.toLowerCase();//獲取瀏覽器用戶代理
var isIPhone = sUA.indexOf("iphone") > -1;
var isAndroid = sUA.indexOf("android") > -1 && sUA.indexOf("linux")>-1;
var isIPod = sUA.indexOf("ipod") > -1;
var isIPad = sUA.indexOf("ipad") > -1;
var isWP = sUA.indexOf("windows phone") > -1 ;
var isSymbian = sUA.indexOf( "symbian")> -1; //完善諾基亞塞班判斷
var isWin = sUA.indexOf( "win" ) > -1 ;
var isLinux =!isAndroid && (sUA.indexOf("linux")> -1);
var isMac = (sUA.indexOf("mac os x") > -1 || sUA.indexOf("macintosh") > -1);
if((!isMac && !isIPhone && !isIPod && !isIPad && !isWP && !isAndroid) || (isWin && !isWP) || (isLinux && !isAndroid) || !isSymbian){return "PC";}
if(isIPhone && !isIPad && !isIPod){
if(sUA.indexOf("iphone os 2") > -1 ){
return "iPhone 3G";
}
if(sUA.indexOf("iphone os 3") > -1 || sUA.indexOf("3gs") > -1){
return "iPhone 3GS";
}
if(sUA.indexOf("iphone os 4") > -1 || sUA.indexOf("ios 4") > -1){
return "iPhone 4";
}
if (sUA.indexOf("iphone os 5") > -1 || sUA.indexOf("ios 5") > -1
|| sUA.indexOf("iphone os 6") > -1)
{
return "iPhone 4s";
}
return "iPhone";
}
if(isIPad){
return "iPad";
}
if(isIPod){
return "iPod";
}
if(isAndroid){
return "Android";
}
if(isSymbian){
return "Symbian";
}
if(isWP){
return "Window Phone";
}
if(isMac){
return "Mac";
}
return "Unknown";
}
//客戶機判斷
function PC_or_Mobile(){
var system={
win:false,
mac:false,
xll:false,
isPad:false //客戶要求pad要跳到pc端。正常狀況pad應該跳到移動端。(只實驗了androidPad)
};
var p=navigator.platform;
var sUA=navigator.userAgent.toLowerCase();
system.win=p.indexOf("Win")==0;
system.mac=p.indexOf("Mac")==0;
system.x11=(p=="X11")||(p.indexOf("Linux")==0);
system.isPad=(p.toLowerCase()=="ipad")||(sUA.indexOf("ipad")>-1);
if(system.win||system.mac||system.xll||system.isPad){
window.location.href="pc/portal.html"
}else{
window.location.href="mobile/portal.html"
}};
麻煩大神給糾錯。