JavaScript: Calculate font-size on mobile devices

As I am making a HTML5 app for android devices using the Intel XDK I ran into a problem with the fonts. I use only em thinking that would work great on any screen size since its relative. I soon realized that it didn’t and that the text got reeeaally small on my phone when I uploaded the app. The reason seems to be zoom-related but I can’t swear to what the problem is aside from the fact that the screen has around 800px width and the standard font-size is still 16px which makes it unreadable. So I had to calculate the size myself and I found that the following formula worked like a charm:

 

var fontSize = Math.round(window.innerWidth * 0.04);
$('body').css('font-size', fontSize + "px");

This sets your font to a relatively easy reading size. Change the percentage if you need to alter the size!