Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
Some Google Fonts don't work on iFrame innerHTML

it's really strange, but my iFrame innerHTML doesn't accept some fonts.

Here is an example of my code:

This font works:

Head:

<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">

Body:

<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>

And this font doesn't work (I have marked the two differences with two **):

Head:

<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">**

Body:

<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>

I really don't understand why the font below doesn't work, do you have an idea?

Edit: In the inspector Raleway is displayed as font, but the displayed font on the site is different (see image below). Image

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is how you can change the font:

<iframe id="textBox" name="iFrameName"></iframe>

Import a font:

iFrameName.document.body.innerHTML = "<style>@import url('https://fonts.googleapis.com/css2?family=Raleway&display=swap');*{font-family:'Raleway',sans-serif;}</style>Some Text";

Use a installed font:

iFrameName.document.body.fontFamily = "Arial";
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!