Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript get default font size for browser [duplicate]

I am trying to get the fontsize and fontfamily that my browser uses to display alerts, prompts etc. So I do:
alert(document.body.style.fontFamily); but it shows me a blank alert. Where am I going wrong?

like image 239
Victor Avatar asked Aug 27 '26 11:08

Victor


1 Answers

Well, I agree with what Kolink says above, but there something you may also want to try:

<body id="body">
<script>
var theCSSprop = window.getComputedStyle(document.body,null).getPropertyValue("font-family");
console.log(theCSSprop); // output: serif
</script>
</body>

With the above code, once you open your FF and change the Proportional setting, you may see the out put is also changed. Have fun :)

enter image description here

like image 155
what Avatar answered Aug 30 '26 01:08

what



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!