'click play button iframe react
Solution 1:[1]
Unfortunately, there is no way to access the elements inside the iframe being loaded from a third-party resource.
Solution 2:[2]
There is a way, example: declare a boolean state and append autoplay=1
to the url on click. Only works for web browsers.
const [play, setPlay] = useState(false);
const url = play ? "urEmbededUrl?autoplay=1" : urEmbededUrl
<iframe
src={url}
title={""}
height="100%"
width="100%"
allow="autoplay;"
/>
<button onClick={() => setPlay(true)}>play</button>
Note that allow="autoplay;"
is required.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Griha Mikhailov |
Solution 2 |