Category: CSS

JQuery script to detect Android device

I needed to create a way of detecting whether my application was running on an Android device, as an Android device does not cope with the command ‘window.print(), although the user may still go to the Android browser menu and click print to reveal the same option.

The way I did this was to create the following script:

$(document).ready(function() {
 var ua = navigator.userAgent.toLowerCase();
 var isAndroid = ua.indexOf("android") > -1;
 // If Android then do something
 if (isAndroid) {
    // Find class <strong>.printButton</strong> and add 2 new styles to it
    $(".printButton").css({
        "visibility": "hidden",
        "display": "none"
    });
   }
});

The CSS for .printButton before the script runs looks like this:

.printButton {
 font-size: 16px;
 float: left;
 color: black;
}

After the script runs, .printButton acts like this:

.printButton {
 visibility: hidden;
 display: none;
 font-size: 16px;
 float: left;
 color: black;
}

Link showing the above in action within JSfiddle

Bootstrap 3.0 Collapse iOS, ipad, iphone issue

I’ve just come across this issue with iOS devices and Bootstrap.
The Collapse function does not work if you use a DIV tag :

<div class="chevron-toggle collapsed" data-toggle="collapse" 
 href="#@unit.ExtraInformationDivId" aria-expanded="false"
 aria-controls="collapseUnit1"></div>

But it does work if you use an A tag or a Button :

<a class="chevron-toggle collapsed" data-toggle="collapse" 
 href="#@unit.ExtraInformationDivId" aria-expanded="false"
 aria-controls="collapseUnit1"></a>

or

<button class="chevron-toggle collapsed" data-toggle="collapse"
 href="#@unit.ExtraInformationDivId" aria-expanded="false"
 aria-controls="collapseUnit1"></button>

If it is to be used inside a Table, then you need to do it like:

Then remove the buttons styling:

.chevron-toggle {
 outline: 0;
 border: none;
 float: right;
 /* Add some extra padding around the button, for larger fingered people */
 padding: 1px 10px 1px 20px;
 background: none;
}

Then the remainder of the code is the same:

<div class="collapse" id="@unit.ExtraInformationDivId" style="position: relative;
 z-index: 3000;">
 <div class="well UnitDetail">
     simple collapse – lorem ipsum dolor sit amet, consectetur adipiscing elit.
     vestibulum facilisis felis in metus vehicula, vitae sagittis quam scelerisque.
     nullam ornare ante ac ipsum dictum, nec imperdiet purus porttitor.
     cras nec auctor tortor. cras posuere odio volutpat mauris facilisis,
     at luctus magna egestas. sed accumsan dolor non ante pellentesque, et pretium
     quam imperdiet. ut vitae dolor nisl. suspendisse porttitor.
  <p><strong><br/><a href="http://www.google.co.uk/search"
   target="_blank">What to do next?</a></strong></p>
 </div>
</div>

This part from above is used to fix Boostrap Collapse within IE browsers.

  
style="position: relative; z-index: 3000;"

Hope it helps, I couldn’t find the information anywhere else.