鍍金池/ 問答/iOS  Android  HTML/ js獲取手機在默認字體

js獲取手機在默認字體

嵌入到手機內的html頁面,如何獲取系統(tǒng)默認字體,大家有用到過的嗎?

回答
編輯回答
乖乖瀦

在我andrio手機上測試有效

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    
    </style>
</head>
<body>
    <div id="div">rfgdfdgdghfgsgfg</div>
    <div id="font"></div>
</body>
<script>
    window.onload = function(){
        const div = document.getElementById('div');
        const font = document.getElementById('font');
        // console.dir(div.style.fontFamily);
        function getFontFamily(elem) {
        var computedStyles = window.getComputedStyle(elem);
        console.log(computedStyles['font-family']);
        font.innerText = computedStyles['font-family'];
        }
        getFontFamily(div);
    }
    
</script>
</html>
2018年6月9日 00:23