簡體   English   中英

jQuery Mobile我有兩個頁面,一個是android,另一個是iphone。 如何檢測瀏覽器並分配瀏覽器?

[英]Jquery Mobile I have two page one for android and one for iphone. How can i detect the browser and assign them?

我對jQuery Mobile有疑問。 我正在為Android和iPhone構建瀏覽器頁面。 我在兩個不同的HTML文件中創建了兩個頁面。 但是我想有一個文件,我想為Android頁面分配android瀏覽器,為iphone頁面分配iphone瀏覽器,並相應地加載它們。

下面是代碼

安卓系統

!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
     <title>Android</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
    <link rel="stylesheet" href="my.css" />
    <style>
        /* App custom styles */
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
    </script>
    <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js">
    </script>
</head>
<body>
    <div data-role="page" data-theme="a" id="page1">
        <div data-theme="b" data-role="header">
        </div>
        <div data-role="content">
            <div>
                <h1 class="text-align-center">
                    <b>
                        Apple
                    </b>
                </h1>
            </div>
            <div>

                </div>
            </div>
            <a data-role="button" data-transition="none" data-theme="b" href="http:m.apple.com">
                Go
            </a>
        </div>
    </div>
    <script>
        //App custom javascript
    </script>
</body>

對於iPhone,它是

<!DOCTYPE html>
<html>
<head>
<title>Apple</title>
<!-- the three things that jQuery Mobile needs to work -->
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
    <link rel="stylesheet" href="iphone.css" />
    <style>
        /* App custom styles */
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
    </script>
    <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js">
    </script>
    <script type="text/javascript" src="mobiledetect.js"></script> 

<!-- This is the first page -->
<section id="firstpage" data-transition="flip" data-theme="b" data-role="dialog">
     <div data-role="content">
            <div>
                <h1 class="text-align-center">
                    <b>
                        Apple
                    </b>
                </h1>
            </div>

            <a data-role="button" data-transition="flip" data-theme="b" href="http://m.apple.com">
                Go
            </a>
        </div>

</section>

Make both pages in same document with different ids (androidPage and iosPage) then  

寫一個javascript函數並在加載頁面之前調用它。 在此功能中,檢查用戶代理,如果用戶代理匹配到android,則加載android頁面;如果匹配到ios,則加載ios頁面。 Android的用戶代理字符串(HTC要求)為

Mozilla / 5.0(Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build / ERE27)AppleWebKit / 530.17(KHTML,like Gecko)Version / 4.0 Mobile Safari / 530.17

而ios(Iphone)的用戶代理是

Mozilla / 5.0(iPhone; U; CPU iPhone OS 4_0,例如Mac OS X; zh-cn)AppleWebKit / 532.9(KHTML,例如Gecko)版本/4.0.5移動版/ 8A293 Safari / 6531.22.7

您可以通過這種方式獲得用戶代理

用戶代理

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM