How to generate embedded code in ReactJS?
up vote
2
down vote
favorite
I want to generate an embedded code from my ReactJS application. I really don't know how can I achieve such functionality?
for example, I want to generate a code which can be used in another website using the iframe, same like youtube embedded code.
Thanks in advance.
javascript reactjs
add a comment |
up vote
2
down vote
favorite
I want to generate an embedded code from my ReactJS application. I really don't know how can I achieve such functionality?
for example, I want to generate a code which can be used in another website using the iframe, same like youtube embedded code.
Thanks in advance.
javascript reactjs
1
Why doesn't this have the javascript tag? reactjs is not a standalone tag
– Electrox Mortem
Nov 9 at 4:37
yeah! forgot to add. Thanks!
– Jagdeesh Kumar
Nov 9 at 4:48
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I want to generate an embedded code from my ReactJS application. I really don't know how can I achieve such functionality?
for example, I want to generate a code which can be used in another website using the iframe, same like youtube embedded code.
Thanks in advance.
javascript reactjs
I want to generate an embedded code from my ReactJS application. I really don't know how can I achieve such functionality?
for example, I want to generate a code which can be used in another website using the iframe, same like youtube embedded code.
Thanks in advance.
javascript reactjs
javascript reactjs
edited Nov 9 at 4:47
asked Nov 9 at 4:28
Jagdeesh Kumar
383116
383116
1
Why doesn't this have the javascript tag? reactjs is not a standalone tag
– Electrox Mortem
Nov 9 at 4:37
yeah! forgot to add. Thanks!
– Jagdeesh Kumar
Nov 9 at 4:48
add a comment |
1
Why doesn't this have the javascript tag? reactjs is not a standalone tag
– Electrox Mortem
Nov 9 at 4:37
yeah! forgot to add. Thanks!
– Jagdeesh Kumar
Nov 9 at 4:48
1
1
Why doesn't this have the javascript tag? reactjs is not a standalone tag
– Electrox Mortem
Nov 9 at 4:37
Why doesn't this have the javascript tag? reactjs is not a standalone tag
– Electrox Mortem
Nov 9 at 4:37
yeah! forgot to add. Thanks!
– Jagdeesh Kumar
Nov 9 at 4:48
yeah! forgot to add. Thanks!
– Jagdeesh Kumar
Nov 9 at 4:48
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
You can do that with below steps.
1.Add DOM element container to contain your component
<!-- ... Your HTML code ... -->
<div id="example_container"></div>
<!-- ...Your HTML code ... -->
The div tag will help us to find out this element from our script code to render our desired react code within it.
2. Add your react script.Please make sure you load react before your script.
<!-- Load react scripts -->
<!-- Load our React component. -->
<script src="example.js"></script>
3. After your code in example.js
which has ExampleReactClass
extends React.Component
and const e = React.createElement;
add the below lines to fix your code in mentioned <div>
const domContainer = document.querySelector('#example_container');
ReactDOM.render(e(ExampleReactClass), domContainer);
Hope it will work!!
thanks for your comment. let me try if it works for me :). I will not forget to accept and upvote your answer.
– Jagdeesh Kumar
Nov 9 at 5:18
1
Please do find the updated edit for better clarity for other parameters :)
– Aman sharma
Nov 9 at 5:26
add a comment |
up vote
0
down vote
Since the question has example of youtube, lets start with that.
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Our main concern is the src
attribute, rest of the iframe attributes can be considered if needed.
To make things easier we need to have Router to handle the embed url request from iframe
import { BrowserRouter } from 'react-router-dom'
ReactDOM.render((
<BrowserRouter>
<App />
</BrowserRouter>
), document.getElementById('root'))
Add a route to handle /embed/h04NnnUApaM
<Route path='/embed/:id' component={YourComponent}/>
Get the embed id in YourComponent
like this props.match.params.number
render the component, and it should show in the iframe.
Generate embed code
Depends on what you want to embed.
<textarea>{this.state.embedCode}<textarea>
embedCode
will be something like this for the above example (id depends on what you need to render your component from the embeded page)
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM"></iframe>
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can do that with below steps.
1.Add DOM element container to contain your component
<!-- ... Your HTML code ... -->
<div id="example_container"></div>
<!-- ...Your HTML code ... -->
The div tag will help us to find out this element from our script code to render our desired react code within it.
2. Add your react script.Please make sure you load react before your script.
<!-- Load react scripts -->
<!-- Load our React component. -->
<script src="example.js"></script>
3. After your code in example.js
which has ExampleReactClass
extends React.Component
and const e = React.createElement;
add the below lines to fix your code in mentioned <div>
const domContainer = document.querySelector('#example_container');
ReactDOM.render(e(ExampleReactClass), domContainer);
Hope it will work!!
thanks for your comment. let me try if it works for me :). I will not forget to accept and upvote your answer.
– Jagdeesh Kumar
Nov 9 at 5:18
1
Please do find the updated edit for better clarity for other parameters :)
– Aman sharma
Nov 9 at 5:26
add a comment |
up vote
0
down vote
You can do that with below steps.
1.Add DOM element container to contain your component
<!-- ... Your HTML code ... -->
<div id="example_container"></div>
<!-- ...Your HTML code ... -->
The div tag will help us to find out this element from our script code to render our desired react code within it.
2. Add your react script.Please make sure you load react before your script.
<!-- Load react scripts -->
<!-- Load our React component. -->
<script src="example.js"></script>
3. After your code in example.js
which has ExampleReactClass
extends React.Component
and const e = React.createElement;
add the below lines to fix your code in mentioned <div>
const domContainer = document.querySelector('#example_container');
ReactDOM.render(e(ExampleReactClass), domContainer);
Hope it will work!!
thanks for your comment. let me try if it works for me :). I will not forget to accept and upvote your answer.
– Jagdeesh Kumar
Nov 9 at 5:18
1
Please do find the updated edit for better clarity for other parameters :)
– Aman sharma
Nov 9 at 5:26
add a comment |
up vote
0
down vote
up vote
0
down vote
You can do that with below steps.
1.Add DOM element container to contain your component
<!-- ... Your HTML code ... -->
<div id="example_container"></div>
<!-- ...Your HTML code ... -->
The div tag will help us to find out this element from our script code to render our desired react code within it.
2. Add your react script.Please make sure you load react before your script.
<!-- Load react scripts -->
<!-- Load our React component. -->
<script src="example.js"></script>
3. After your code in example.js
which has ExampleReactClass
extends React.Component
and const e = React.createElement;
add the below lines to fix your code in mentioned <div>
const domContainer = document.querySelector('#example_container');
ReactDOM.render(e(ExampleReactClass), domContainer);
Hope it will work!!
You can do that with below steps.
1.Add DOM element container to contain your component
<!-- ... Your HTML code ... -->
<div id="example_container"></div>
<!-- ...Your HTML code ... -->
The div tag will help us to find out this element from our script code to render our desired react code within it.
2. Add your react script.Please make sure you load react before your script.
<!-- Load react scripts -->
<!-- Load our React component. -->
<script src="example.js"></script>
3. After your code in example.js
which has ExampleReactClass
extends React.Component
and const e = React.createElement;
add the below lines to fix your code in mentioned <div>
const domContainer = document.querySelector('#example_container');
ReactDOM.render(e(ExampleReactClass), domContainer);
Hope it will work!!
edited Nov 9 at 5:25
answered Nov 9 at 5:12
Aman sharma
776
776
thanks for your comment. let me try if it works for me :). I will not forget to accept and upvote your answer.
– Jagdeesh Kumar
Nov 9 at 5:18
1
Please do find the updated edit for better clarity for other parameters :)
– Aman sharma
Nov 9 at 5:26
add a comment |
thanks for your comment. let me try if it works for me :). I will not forget to accept and upvote your answer.
– Jagdeesh Kumar
Nov 9 at 5:18
1
Please do find the updated edit for better clarity for other parameters :)
– Aman sharma
Nov 9 at 5:26
thanks for your comment. let me try if it works for me :). I will not forget to accept and upvote your answer.
– Jagdeesh Kumar
Nov 9 at 5:18
thanks for your comment. let me try if it works for me :). I will not forget to accept and upvote your answer.
– Jagdeesh Kumar
Nov 9 at 5:18
1
1
Please do find the updated edit for better clarity for other parameters :)
– Aman sharma
Nov 9 at 5:26
Please do find the updated edit for better clarity for other parameters :)
– Aman sharma
Nov 9 at 5:26
add a comment |
up vote
0
down vote
Since the question has example of youtube, lets start with that.
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Our main concern is the src
attribute, rest of the iframe attributes can be considered if needed.
To make things easier we need to have Router to handle the embed url request from iframe
import { BrowserRouter } from 'react-router-dom'
ReactDOM.render((
<BrowserRouter>
<App />
</BrowserRouter>
), document.getElementById('root'))
Add a route to handle /embed/h04NnnUApaM
<Route path='/embed/:id' component={YourComponent}/>
Get the embed id in YourComponent
like this props.match.params.number
render the component, and it should show in the iframe.
Generate embed code
Depends on what you want to embed.
<textarea>{this.state.embedCode}<textarea>
embedCode
will be something like this for the above example (id depends on what you need to render your component from the embeded page)
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM"></iframe>
add a comment |
up vote
0
down vote
Since the question has example of youtube, lets start with that.
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Our main concern is the src
attribute, rest of the iframe attributes can be considered if needed.
To make things easier we need to have Router to handle the embed url request from iframe
import { BrowserRouter } from 'react-router-dom'
ReactDOM.render((
<BrowserRouter>
<App />
</BrowserRouter>
), document.getElementById('root'))
Add a route to handle /embed/h04NnnUApaM
<Route path='/embed/:id' component={YourComponent}/>
Get the embed id in YourComponent
like this props.match.params.number
render the component, and it should show in the iframe.
Generate embed code
Depends on what you want to embed.
<textarea>{this.state.embedCode}<textarea>
embedCode
will be something like this for the above example (id depends on what you need to render your component from the embeded page)
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM"></iframe>
add a comment |
up vote
0
down vote
up vote
0
down vote
Since the question has example of youtube, lets start with that.
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Our main concern is the src
attribute, rest of the iframe attributes can be considered if needed.
To make things easier we need to have Router to handle the embed url request from iframe
import { BrowserRouter } from 'react-router-dom'
ReactDOM.render((
<BrowserRouter>
<App />
</BrowserRouter>
), document.getElementById('root'))
Add a route to handle /embed/h04NnnUApaM
<Route path='/embed/:id' component={YourComponent}/>
Get the embed id in YourComponent
like this props.match.params.number
render the component, and it should show in the iframe.
Generate embed code
Depends on what you want to embed.
<textarea>{this.state.embedCode}<textarea>
embedCode
will be something like this for the above example (id depends on what you need to render your component from the embeded page)
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM"></iframe>
Since the question has example of youtube, lets start with that.
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Our main concern is the src
attribute, rest of the iframe attributes can be considered if needed.
To make things easier we need to have Router to handle the embed url request from iframe
import { BrowserRouter } from 'react-router-dom'
ReactDOM.render((
<BrowserRouter>
<App />
</BrowserRouter>
), document.getElementById('root'))
Add a route to handle /embed/h04NnnUApaM
<Route path='/embed/:id' component={YourComponent}/>
Get the embed id in YourComponent
like this props.match.params.number
render the component, and it should show in the iframe.
Generate embed code
Depends on what you want to embed.
<textarea>{this.state.embedCode}<textarea>
embedCode
will be something like this for the above example (id depends on what you need to render your component from the embeded page)
<iframe width="560" height="315" src="https://www.yoursite.com/embed/h04NnnUApaM"></iframe>
answered Nov 9 at 5:48
kiranvj
12.1k23350
12.1k23350
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219882%2fhow-to-generate-embedded-code-in-reactjs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why doesn't this have the javascript tag? reactjs is not a standalone tag
– Electrox Mortem
Nov 9 at 4:37
yeah! forgot to add. Thanks!
– Jagdeesh Kumar
Nov 9 at 4:48