0

jQuery Mobile に疑問があります。Android と iPhone 用のブラウザ ページを作成しています。両方のページを 2 つの異なる HTML ファイルで作成しました。しかし、私は1つのファイルが必要で、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>

4

1 に答える 1

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

javascript関数を記述し、ページをロードする前に呼び出します。この関数では、ユーザーエージェントをチェックします。ユーザーエージェントがandroidに一致する場合は、androidページをロードし、iosに一致する場合は、iosページをロードします。android(HTCdesire)のユーザーエージェント文字列は

Mozilla / 5.0(Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build / ERE27)AppleWebKit / 530.17(KHTML、Geckoなど)バージョン/4.0モバイルSafari / 530.17

iOS(iPhone)のユーザーエージェントは

Mozilla / 5.0(iPhone; U; MacOSXのようなCPUiPhoneOS 4_0; en-us)AppleWebKit / 532.9(GeckoのようなKHTML)バージョン/4.0.5モバイル/ 8A293Safari / 6531.22.7

この方法でユーザーエージェントを取得できます

ユーザーエージェント

于 2012-05-06T07:04:42.253 に答える