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

240
Views
How do I export mongodb html code to html file?

How do I display an html data piece from mongo db correctly?

Data: The html was encoded

What it shows: Not showing correctly

Code:

<script defer>
      function decodeHtml(html) {
    var txt = document.createElement("textarea");
    txt.innerHTML = html;
    return txt.value;
}
      
    const description = document.getElementById("descontainer")

    description.innerHTML += decodeHtml('<%= post.post.description %>')
 </script>

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

0

Not really sure why you put that html on a textarea element. But if the content is comming from a database that is contain use generated content, then you probele need an html sanitizer like dompurify.

You will use it like this:


<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.3.6/purify.min.js" integrity="sha512-DJjvM/U3zCRpzrYboJgg23iLHapWcS2rlo7Ni18Cdv+FMs6b3gUF7hQihztj4uVkHHfUwk7dha97jVzRqUJ7hg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script defer>
   function decodeHtml(html) {
            
      return DOMPurify.sanitize(html);;
   }
          
   const description = document.getElementById("descontainer")

   description.innerHTML += decodeHtml('<%= post.post.description %>')
</script>

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!