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

224
Views
Iframe no carga el css desde la etiqueta del enlace en el mismo dominio en el navegador Chrome

Estoy agregando dinámicamente un iframe al documento html usando javascript .

 var iframe = document.createElement('iframe'); document.body.appendChild(iframe); iframe.contentWindow.document.body.innerHTML = document.querySelector('#section-to-print').innerHTML;

Cuando agrego css usando la etiqueta de link del same domain al encabezado del iframe , los estilos no se cargan.

 let link = document.createElement("link"); link.href = "https://localhost:5001/css/invoice-receipt.css"; /**** your CSS file ****/ link.rel = "stylesheet"; link.type = "text/css"; iframe.contentWindow.document.head.appendChild(link);

Pero cuando agrego el css usando la etiqueta de style , funciona.

 var styles = document.createElement("style"); styles.innerHTML = `html, body { width: 2.7in; margin: 0 auto; height: max-content; }`; iframe.contentWindow.document.head.appendChild(styles);

El problema es que quiero cargar una hoja de estilo diferente dinámicamente, pero la carga a través de un enlace no funciona. Por favor ayuda en lo que me estoy perdiendo.

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

0

Hice que esto funcionara usando el siguiente script .

 var bodyScript = document.createElement("script"); bodyScript.innerHTML = `fetch('https://localhost:5001/css/invoice-receipt.css') .then(response => response.text()) .then(data => { var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text/css'; style.appendChild(document.createTextNode(data)); });`; iframe.contentWindow.document.body.appendChild(bodyScript);
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!