Griha Mikhailov
Griha Mikhailov

Reputation: 733

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

Upvotes: 0

Views: 1311

Answers (2)

Drew Cordano
Drew Cordano

Reputation: 1120

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.

Upvotes: 1

Griha Mikhailov
Griha Mikhailov

Reputation: 733

Unfortunately, there is no way to access the elements inside the iframe being loaded from a third-party resource.

Upvotes: 0

Related Questions