原文

測試網址
http://dbhills.blogspot.com/p/typetextjavascript-var-url-document.html
功能為網頁自動轉址及判斷是否為手機瀏覽,可以用於智慧轉址。開啟網頁會去判斷用Android、ipad、iphone或PC何種作業系統裝置開啟網頁,並自動依照裝置不同連結不同網頁。

程式碼如下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script type="text/javascript">

var URL = document.location.toString();
var useragent = navigator.userAgent;
useragent = useragent.toLowerCase();

if( useragent.indexOf('iphone') != -1 ) location.replace("https://itunes.apple.com/us/app/li-da-zi-xun-xing-dongapp/id665035983?l=zh&ls=1&mt=8");//iphone
else if( useragent.indexOf('ipad') != -1 || useragent.indexOf('ipod') != -1) location.replace("https://itunes.apple.com/us/app/li-da-zi-xun-xing-dongapp/id665035983?l=zh&ls=1&mt=8");//ipad
else if( useragent.indexOf('android') != -1 ) {
if( ConsiderLimits() )
{
location.replace("https://play.google.com/store/apps/details?id=tw.com.giantapp.sample"); // android pad
}else{
location.replace("https://play.google.com/store/apps/details?id=tw.com.giantapp.sample"); // android phone
}
}else{
location.replace("http://www.e-giant.com.tw/"); // PC
}

function ConsiderLimits() {
if( screen.width >= 1024 && screen.height >= 600 )
return 1;
return 0;
}

</script>
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()