Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute Script tag in Parser #98

Closed
frontendpm opened this issue Mar 26, 2019 · 5 comments
Closed

Execute Script tag in Parser #98

frontendpm opened this issue Mar 26, 2019 · 5 comments
Labels
question Further information is requested

Comments

@frontendpm
Copy link

frontendpm commented Mar 26, 2019

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_no="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>')
Unfortunately this library is not loaded to the browser. Did I do something wrong?

@remarkablemark
Copy link
Owner

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.

@remarkablemark remarkablemark added the question Further information is requested label Mar 27, 2019
@remarkablemark
Copy link
Owner

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

@frontendpm
Copy link
Author

Thank mate, it works perfectly!

@rinkusam12
Copy link

How should I do this in NextJS

@lhguerra
Copy link

A little late pherhaps but in Next JS you would use the Script component: https://nextjs.org/docs/api-reference/next/script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants