Custer
Custer

Reputation: 145

React.js iframe src

index.js

import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
    render() {
        return (
            <div>
                <h1>Outside iFrame</h1>
                <iframe title="myiframe" src="./target.html" width="600px" height="400px"></iframe>
            </div>
        )
    }
}

ReactDOM.render(<App />, document.getElementById('root'));

index.html

<div id="root"></div>

target.html

<html>

<head></head>

<body>
    <h1>Inside IFrame</h1>
</body>

</html>

the Problem is like this:

enter image description here

what's wrong with the code?

Upvotes: 3

Views: 10415

Answers (1)

Saurabh Gour
Saurabh Gour

Reputation: 753

You are getting this issue because the relative url src="./target.html" is incorrect. To make sure you are using the correct url, please individually check the url generated for index.html and target.html. Also make sure that you are not making a typo error.

I tried running your code and it works fine if your target.html and index.html urls are as follows :

target.html

index.html

I can also recreate your issue, if I make a typo error in my code like so src="./typoerror.html" ,

Typo error case

Upvotes: 2

Related Questions