0

エンド ユーザーが使用しているデバイスに応じて、正しいスクリプトを表示し、このコードの誤ったスクリプトを非表示にしたいと考えています。

    <ul class="pageitem">
<li class="button iphone"><input name="Submit" value="App Downloads" onclick="window.location='appiphone.html' " type="submit" /></li>
<li class="button ipad"><input name="Submit" value="App Downloads" onclick="window.location='appipad.html' " type="submit" /></li>
<li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='appandroid.html' " type="submit" /></li>
</ul>

これで、デバイスを特定のページにリダイレクトするこのコードができましたが、これ以上は必要ありません。

<script type="text/javascript">
if (screen.width>801)
{
window.location="http://www.xclo.co.uk/PC.html"
}
</script>
<script type="text/javascript"> // <![CDATA[
    if ( (navigator.userAgent.indexOf('Android') != -1) ) {
        document.location = "android.html";
    } // ]]>
</script>
<script type="text/javascript"> 
var iphone = ((window.navigator.userAgent.match('iPhone'))||(window.navigator.userAgent.match('iPod')))?true:false;
var ipad = (window.navigator.userAgent.match('iPad'))?true:false;
if(iphone){
 document.location = 'iphone.html';
}
if(ipad){
 document.location = 'ipad.html';
}
</script>

このスクリプトを取得して、関連するコンテンツを表示し、リダイレクトしないようにする方法を教えてください。

ありがとうございました。

4

1 に答える 1

0

これを試して:

<ul class="pageitem">
    <li class="button iphone" id="iphone"><input name="Submit" value="App Downloads" onclick="window.location='appiphone.html';" type="submit" /></li>

    <li class="button ipad" id="ipad"><input name="Submit" value="App Downloads" onclick="window.location='appipad.html';" type="submit" /></li>

    <li class="button android" id="android"><input name="Submit" value="App Downloads" onclick="window.location='appandroid.html';" type="submit" /></li>
</ul>

<script type="text/javascript">
    function mayShowElement(id, shouldShow)
    {
        document.getElementById(id).style.display = shouldShow ? 'block' : 'none';
    }

    var userAgent = window.navigator.userAgent;

    var MOBILE = {
        IS_IPHONE : userAgent.match('iPhone') || userAgent.match('iPod'),
        IS_IPAD   : userAgent.match('iPad'),
        IS_IPHONE : userAgent.indexOf('Android') != -1
    };

    mayShowElement('iphone', MOBILE.IS_IPHONE);
    mayShowElement('ipad', MOBILE.IS_IPAD);
    mayShowElement('android', MOBILE.IS_ANDROID);
</script>

これは、コードに基づいた良い解決策 (テストされていない) のようです。

于 2013-05-21T22:13:06.327 に答える