Html-react-parser: Execute Script tag in Parser

Created on 26 Mar 2019  ·  4Comments  ·  Source: remarkablemark/html-react-parser

Hi,
is it possible to parse script tag? In my case I get the html code with script tag as a string from some endpoint, and I wish to put it into my react component and make it works.

So for example on the end I am trying to do something similar to this:
Parser('<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>')
Unfortunately this library is not loaded to the browser. Did I do something wrong?

question

Most helpful comment

Although <script> markup is parsed by html-react-parser, it actually isn't rendered by react-dom.

I recently discovered this while troubleshooting #94.

To load a script, you will need to programmatically create and append a script element using replace. See fiddle.

All 4 comments

Although <script> markup is parsed by html-react-parser, it actually isn't rendered by react-dom.

I recently discovered this while troubleshooting #94.

To load a script, you will need to programmatically create and append a script element using replace. See fiddle.

Was your question answered @frontendpm? Let me know what else you need in order to close the issue.

Thank mate, it works perfectly!

How should I do this in NextJS

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dave-stevens-net picture dave-stevens-net  ·  9Comments

thany picture thany  ·  7Comments

ollie-o picture ollie-o  ·  3Comments

mdeljavan picture mdeljavan  ·  4Comments

poacher2k picture poacher2k  ·  14Comments