Skip to content

Instantly share code, notes, and snippets.

@LucaColonnello
Last active August 29, 2015 14:08
Show Gist options
  • Save LucaColonnello/d10f18166640433a1e6f to your computer and use it in GitHub Desktop.
Save LucaColonnello/d10f18166640433a1e6f to your computer and use it in GitHub Desktop.
Calculate base font size
// device base font size
window.getDeviceBaseFontSize = function( ) {
// check getted yet
if( !window.__baseDeviceFontSize ) {
window.__baseDeviceFontSize = 0;
var iframe = document.createElement( "IFRAME" );
iframe.style.display = "none";
document.body.appendChild( iframe );
var s = "<html><body><"+"/body><"+"/html>";
iframe.contentWindow.document.body.innerHTML = s;
window.parent.__baseDeviceFontSize = Number(getComputedStyle(iframe.contentWindow.document.body, '').fontSize.match(/(\d+(\.\d*)?)px/)[1]);
document.body.removeChild( iframe );
}
return window.__baseDeviceFontSize;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment