-3

条件付きの JavaScript コードが必要です。

display:none コードを設定する必要はありません。それはすでに動作します。しかし、html/body クラスに基づいたコードが必要です。

body/html クラスが「gecko」の場合、Firefox の div のみを表示し、他のすべての div をページから削除します。お気に入り:

 <body class="gecko">
 <div id="firefox"></div>
 <div id="ie"></div> [need to remove this]
 <div id="chrome"></div> [need to remove this]
 <div id="safari"></div> [need to remove this]
 </body>

body/html クラスが chrome の場合、chrome div のみを表示し、他のすべての div をページから削除します。

<body class="chrome">
<div id="firefox"></div> [need to remove this]
<div id="ie"></div> [need to remove this]
<div id="chrome"></div>
<div id="safari"></div> [need to remove this]
</body>

body/html クラスが空白の場合、IE div のみを表示し、他のすべての div をページから削除します。

<body>
<div id="firefox">text here</div> [need to remove this]
<div id="ie"></div> 
<div id="chrome"></div> [need to remove this]
<div id="safari"></div> [need to remove this]
</body>

display:none または visibility:hidden コードを設定したくありません。javascript コードを remove() したい。

これを使ってみました。そのすべての主要なブラウザーで動作します。ブラウザを検出し、display:none; を設定します。他のブラウザ用。CSS 部分のデモは、http: //www.downloadsaga.com/inboxace/で見ることができます。しかし、iframeを使用すると、他のdivのiframeがロードされます。そのためには、表示されていないときに iframe を読み込めないコードが必要です。

<?php require('css_browser_selector.php') ?>
<html class="<?php echo css_browser_selector() ?>">
<head>
<title>Browser Detect</title>

<style type="text/css">
.ie #firefox, .ie #chrome, .ie #opera, .ie #safari {
  display:none;
}
.gecko #chrome, .gecko #ie, .gecko #opera, .gecko #safari {
  display:none;
}
.win.gecko #chrome, .win.gecko #ie, .win.gecko #opera, .win.gecko #safari  {
  display:none;
}
.linux.gecko #chrome, .linux.gecko #ie, .linux.gecko #opera, .linux.gecko #safari  {
  display:none;
}
.opera #firefox, .opera #chrome, .opera #ie, .opera #safari  {
  display:none;
}
.safari #firefox, .safari #chrome, .safari #ie, .safari #opera  {
  display:none;
}
.chrome #firefox, .chrome #opera, .chrome #ie, .chrome #safari  {
    display:none;
}
.opera #opera {
display:block;
}
.chrome #chrome {
display:block;
}

html {overflow: auto;}
html, body, div, iframe {margin: 0px; padding: 0px; height: 100%; border: none;}
iframe {display: block; width: 100%; border: none; overflow-y: auto; overflow-x: hidden;} 

</style>


<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    if ($("body").hasClass("gecko")){
    $( "#ie" ).remove();
    $( "#chrome" ).remove();
    $( "#safari" ).remove();
    $( "#opera" ).remove();
    } else if ($("body").hasClass("chrome")) {
    $( "#ie" ).remove();
    $( "#firefox" ).remove();
    $( "#safari" ).remove();
    $( "#opera" ).remove();
    }  else if ($("body").hasClass("")) {
    $( "#chrome" ).remove();
    $( "#firefox" ).remove();
    $( "#safari" ).remove();
    $( "#opera" ).remove();
    }  else if ($("body").hasClass("safari")) {
    $( "#ie" ).remove();
    $( "#firefox" ).remove();
    $( "#chrome" ).remove();
    $( "#opera" ).remove();
    }  else if ($("body").hasClass("opera")) {
    $( "#ie" ).remove();
    $( "#firefox" ).remove();
    $( "#safari" ).remove();
    $( "#chrome" ).remove();
    } 
});
</script>
</head>
<body class="webkit chrome win">
<div id="#content">
    <div id="firefox">
        <iframe src="firefox.html"  frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe>
    </div>
    <div id="chrome">
        <iframe src="google.html"  frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe> 
    </div>
    <div id="ie">
        <iframe src="microsoft.html"  frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe>
    </div>
    <div id="opera">
        <iframe src="opera.html"  frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe>
    </div>
    <div id="safari">
        <iframe src="safari.html"  frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe>
    </div>
</div>
</body>
</html>

専門家による解決策はありますか?? ここに css_browser_selector.php ファイルがあります。 https://github.com/bastianallgeier/PHP-Browser-Selector

4

2 に答える 2

0

Jquery hasClassメソッドを使用できます

$(document).ready(function(){

    if ($("body").hasClass("gecko")){
    // display:none for other than firefox
    } else if ($("body").hasClass("chrome")) {
    // display:none for other than chrome
    } // continue your code
});
于 2013-10-05T09:04:26.863 に答える
-1
  first you will get body attribute class value and then store value variable 
and check if variable value is gecko means firefox div is enable and other divs are disable or 
if variable value is chrome means only chrome div is enable others to be disable 
 last condition for variable value null means is ie div enable and others to be disable
        $(document).ready(function(){
        var className=$("body").attr("class");
        if(className=='gecko')
        {

        $("#firefox").addClass('in');

        $("#ie").removeClass('in');

        $("#chrome").removeClass('in');

        $("#safari").removeClass('in');
        }
        else if(className=='chrome')
        {

        $("#firefox").removeClass('in');

        $("#ie").removeClass('in');

        $("#chrome").addClass('in');

        $("#safari").removeClass('in');
        }
        else if(className=='')
        {

        $("#firefox").removeClass('in');

        $("#ie").addClass('in');

        $("#chrome").removeClass('in');

        $("#safari").removeClass('in');
        }
        });

Using jquery 
first get body tag class attribute value
then check attribute value 
gecko,chrome and null
gecko means firefox div is enable using addClass Property
chrome means chrome div is enable using addClass Property
null means ie div is enable using addClass Property
于 2013-10-05T08:49:32.003 に答える