I need a conditional javascript code.
no need to set display:none code. its already works. but I want the code based on html/body class.
when body/html class is "gecko" only show firefox div and remove all others div from page. Like:
<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>
When body/html class is chrome only show chrome div and remove all others div from page.
<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>
when body/html class is blank only show IE div and remove all others div from page.
<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>
I don't want to set display:none or visibility:hidden code. I want to remove() javascript code.
I tried using this. Its works on all of major browser. detect browser and set display:none; for others browser. You can see the css part demo here: http://www.downloadsaga.com/inboxace/. but its still load iframe for others div when I use iframe. for that I need a code that can't load iframe when its not show.
<?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>
Any Expert solutions?? here you got the css_browser_selector.php file. https://github.com/bastianallgeier/PHP-Browser-Selector