close

How to set iframe content of a react component

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to set iframe content of a react component in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to set iframe content of a react component ?

  1. How to set iframe content of a react component ?

    to set iframe content of a react component There is an easier solution if someone just wants to display small HTML inside the iframe.
    <iframe src={"data:text/html,"+encodeURIComponent(content)}/>
    The max length of content is 32768 characters.

  2. How to set iframe content of a react component ?

    to set iframe content of a react component There is an easier solution if someone just wants to display small HTML inside the iframe.
    <iframe src={"data:text/html,"+encodeURIComponent(content)}/>
    The max length of content is 32768 characters.

Method 1

There is an easier solution if someone just wants to display small HTML inside the iframe.

<iframe src={"data:text/html,"+encodeURIComponent(content)}/>

The max length of content is 32768 characters.

Method 2

This works too (not supported in IE).

const myHTML = <h1>Hello World</h1>
<iframe srcDoc={myHTML} />

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment