how to set width and height of html-page inside <iframe srcDoc={htmlPage}>

Viewed 60

I want to preview the HTML content (which comes from the backend as a string) in my react application. I'm setting the iframe srcDoc as shown below.

<iframe width="100%" height="515px" srcDoc={previewTemplate}></iframe>

the width and height properties are setting the dimensions of the iframe. How to set the width and height of HTML content inside?

NOTE: HTML page is responsive HTML page used can be viewed here

1 Answers

you can use the code below with peace of mind.

<iframe srcDoc={previewTemplate} onload="this.width=screen.width;this.height=screen.height;">
Related