How to set iframe content of a react component

后端 未结 5 2074
走了就别回头了
走了就别回头了 2020-12-22 19:28

I am trying to set the content of an iframe in a React component but I am not able to do it. I have a component in which contains a function which has to be called when the

5条回答
  •  暖寄归人
    2020-12-22 20:09

    Using the DOMParser constructor's parseFromString to parse the html is a little simpler than the accepted answer. Here is an example where the parsed html is retrieved from the DOMParser's generated document. If you're sending an element to the iframe, leave out the .body.innerText part of the parseHtml.

    class SimpleIframe extends Component {
        render() {
            const parseHtml = html => new DOMParser().parseFromString(html, 'text/html').body.innerText;
            return