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

155
Views
Mostrando contenido HTML real en jQuery

Tengo un elemento con contenido html codificado como se muestra a continuación.

 <div class="hasTooltip"> &lt;html&gt;........... //more html encoded text </div>

Cuando hago clic en este elemento, quiero que el contenido se muestre en una nueva ventana y funciona bien.

 $('.hasTooltip').click(function() { var win = window.open("", "Title", "toolbar=no"); win.document.body.innerHTML = $(this).html(); });

Pero el problema es que la ventana muestra el texto html con valores decodificados pero no el contenido html real con todos los estilos.

Probé el siguiente código pero no tuve suerte ya que no muestra contenido. ¿Algun consejo?

 win.document.body.innerHTML = $(this).html().text();
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

El siguiente código debería funcionar.

 function unEscape( str ){ str = str.replace(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>') return str; } var h = document.getElementById("hasTooltip").innerHTML; console.log( unEscape(h) )
 <div id="hasTooltip"> &lt;html&gt;&lt;/html&gt; </div>

over 4 years ago · Santiago Trujillo Report

0

Aquí está tu solución

si no puede ejecutar su código aquí, verifique jsfiddle

https://jsfiddle.net/sq3Ljwnt/

 $('.hasTooltip').click(function() { var win = window.open("", "Title", "toolbar=no"); win.document.body.innerHTML = $("textarea").val(); });
 textarea{ height:200px; width:100%; border:none !important; background:none; resize: none; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <div class="hasTooltip"> <textarea> <html> <h1> This is test </h1> <p> More HTML ... </p> </html> </textarea> </div>

over 4 years ago · Santiago Trujillo 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!