Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
iframe with @fontface url to local file

I need to include a font (Open Sans) in a style tag within an iframe, That I inject dynamically in JS.

The font file is in a local folder. I want to use @font-face like this:

      /* open-sans-regular - latin */
            @font-face {
            font-family: 'Open Sans';
            font-style: normal;
            font-weight: 400;
            src: local(''),                
                url('../fonts/open-sans-v29-latin-regular.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
                url('../fonts/open-sans-v29-latin-regular.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
            }

I create the Iframe like this:

      const frame = document.createElement('iframe');

      overlay.srcdoc = `
            <!doctype html>
            <html>
            <head>     
                <style>

            /* open-sans-regular - latin */
            @font-face {
            font-family: 'Open Sans';
            font-style: normal;
            font-weight: 400;
            src: local(''),                
                url('../fonts/open-sans-v29-latin-regular.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
                url('../fonts/open-sans-v29-latin-regular.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
            }
            /* open-sans-600 - latin */
            @font-face {
            font-family: 'Open Sans';
            font-style: normal;
            font-weight: 600;
            src: local(''),
                url('../fonts/open-sans-v29-latin-600.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
                url('../fonts/open-sans-v29-latin-600.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
            }
  
                    .example{
                        font-family: 'Open Sans';
                    }
                </style>
            </head>
            <body>
                <div id="example">
                    bla bla bla
                </div>
            </body> 
        `;

I inject the iframe to an external domain, but the src URL is not working.

In the console I get the following warning:

Failed to decode downloaded font: https://external_domain_url/fonts/open-sans-v29-latin-600.woff

And of course, the font is not displaying as expected.

What am I doing wrong?

Any help would be appreciated!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda