0

My JS:

window.onload = function(){
    if(/Android|webOS|iPhone|Windows Phone/i.test(this.navigator.userAgent)){
        document.getElementById('datatable').style.fontSize = "10px";
    } else {
        document.getElementById('datatable').style.fontSize = "20px";
    }
}

HTML:

<table class="TFtable" id="datatable">
  ...
</table>

Please note: there are currently no styles to do with font-size which are affecting class 'TFtable'.

ecqo
  • 83
  • 9

3 Answers3

1

You can use CSS media queries to target devices with a viewport of less than 600px.

@media only screen and (max-width: 600px) {
  table.TFtable {
    font-size: /* your smaller font size*/;
  }
}
Ben
  • 3,160
  • 3
  • 17
  • 34
0

From a excelent answer Detecting a mobile browser, here is the solution.

if (typeof window.orientation !== 'undefined') {
    document.getElementById('datatable').style.fontSize = "10px";
}else {
    document.getElementById('datatable').style.fontSize = "20px";
}

as you requested for iPhone only,

here is what you can do

var iOS = !!navigator.platform && /iPhone/.test(navigator.platform);

use this iOS variable, iOS will be a boolean.

Atul Rajput
  • 4,073
  • 2
  • 12
  • 24
  • but keep one thing on mind that this will happy all the mobile and iPad as well, every device which use orientation – Atul Rajput Apr 26 '20 at 12:47
  • is there a way of detecting just iPhones? – ecqo Apr 26 '20 at 12:48
  • if the requirement is to change font only on mobile devices, then CSS option is the best as answered by kaleidawave, it will work all the devices, but if you want to do something with iPhone only then that will not work. – Atul Rajput Apr 26 '20 at 13:06
0
if ($(window).width() < 900) {
   document.getElementById('datatable').style.fontSize = "10px";
}
else{
        document.getElementById('datatable').style.fontSize = "20px";

}

Nourhan Ahmed
  • 179
  • 1
  • 10