Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using iframe tag in react application with local html file

Tags:

reactjs

iframe

What is the best way to use iframe in react application, while having local html file for ifram src.

I need to have an iframe in my react application, but the iframe does not work with my local html file.

function ClusterDetails() {

  return (
    <iframe title='mytitle' src="../../data/index.html" width='500px'  height='500px'></iframe>
  );
}

export default ClusterDetails;
like image 416
mshadi Avatar asked Mar 19 '26 00:03

mshadi


1 Answers

I found the solution. The source of iframe should be placed in public folder. the src attribute of iframe should be addressed related to public folder.

For example if there is a data folder containing index.html file, in public folder, then the src should be set as 'data/index.html'

like image 198
mshadi Avatar answered Mar 20 '26 17:03

mshadi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!