'click play button iframe react

I have an iframe video with a play button (not youtube!). There is no autoplay functionality. So, I want onLoad imitate click this button. How can I achieve this? I know the class of the button, I want to use it.enter image description here



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