某些 Google 字体在 iFrame innerHTML 上不起作用
Some Google Fonts don't work on iFrame innerHTML
真奇怪,我的 iFrame innerHTML 不接受某些字体。
这是我的代码示例:
此字体有效:
负责人:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comforter&display=swap" rel="stylesheet">
正文:
<iframe id="textBox" name="richTextFeld"></iframe>
<script type="text/javascript">
function onLoad() {
richTextFeld.document.designMode = 'On';
richTextFeld.document.body.style.fontFamily = "'Comforter', cursive";
richTextFeld.document.body.style.fontSize = "16px";
richTextFeld.document.body.style.color = "#ff0000";
richTextFeld.document.body.innerHTML = "Some Text";
}
</script>
而且这个字体不行(我用两个**标出了两个不同点):
负责人:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
**<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@200&display=swap" rel="stylesheet">**
正文:
<iframe id="textBox" name="richTextFeld"></iframe>
<script type="text/javascript">
function onLoad() {
richTextFeld.document.designMode = 'On';
**richTextFeld.document.body.style.fontFamily = "'Raleway', sans-serif";**
richTextFeld.document.body.style.fontSize = "16px";
richTextFeld.document.body.style.color = "#ff0000";
richTextFeld.document.body.innerHTML = "Some Text";
}
</script>
我真的不明白为什么下面的字体不起作用,你有什么想法吗?
编辑:Raleway 在检查器中显示为字体,但在网站上显示的字体不同(见下图)。
Image
更改字体的方法如下:
<iframe id="textBox" name="iFrameName"></iframe>
导入字体:
iFrameName.document.body.innerHTML = "<style>@import url('https://fonts.googleapis.com/css2?family=Raleway&display=swap');*{font-family:'Raleway',sans-serif;}</style>Some Text";
使用安装的字体:
iFrameName.document.body.fontFamily = "Arial";
真奇怪,我的 iFrame innerHTML 不接受某些字体。
这是我的代码示例:
此字体有效:
负责人:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comforter&display=swap" rel="stylesheet">
正文:
<iframe id="textBox" name="richTextFeld"></iframe>
<script type="text/javascript">
function onLoad() {
richTextFeld.document.designMode = 'On';
richTextFeld.document.body.style.fontFamily = "'Comforter', cursive";
richTextFeld.document.body.style.fontSize = "16px";
richTextFeld.document.body.style.color = "#ff0000";
richTextFeld.document.body.innerHTML = "Some Text";
}
</script>
而且这个字体不行(我用两个**标出了两个不同点):
负责人:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
**<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@200&display=swap" rel="stylesheet">**
正文:
<iframe id="textBox" name="richTextFeld"></iframe>
<script type="text/javascript">
function onLoad() {
richTextFeld.document.designMode = 'On';
**richTextFeld.document.body.style.fontFamily = "'Raleway', sans-serif";**
richTextFeld.document.body.style.fontSize = "16px";
richTextFeld.document.body.style.color = "#ff0000";
richTextFeld.document.body.innerHTML = "Some Text";
}
</script>
我真的不明白为什么下面的字体不起作用,你有什么想法吗?
编辑:Raleway 在检查器中显示为字体,但在网站上显示的字体不同(见下图)。 Image
更改字体的方法如下:
<iframe id="textBox" name="iFrameName"></iframe>
导入字体:
iFrameName.document.body.innerHTML = "<style>@import url('https://fonts.googleapis.com/css2?family=Raleway&display=swap');*{font-family:'Raleway',sans-serif;}</style>Some Text";
使用安装的字体:
iFrameName.document.body.fontFamily = "Arial";