How to autoplay youtube video from redirect link

Viewed 1319

I have a button that redirects to a youtube video, but the video is always loaded paused. I want the video to start automatically for various reasons (try the link out). Here is my code:

<input type="button" onclick="location.href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'" value="Go">

2 Answers

I know this is a solution with the <iframe> element, but it should work for this as well. At the end of the url, try adding the this autoplay parameter ?autoplay=1

This is not working as simple as it did once in 2021.

Nowadays modern browser block autoplay Chrome as an example

But it can be done in other ways:

If you visit youtube developer site you can see they write


Chrome's autoplay policies are simple:

  1. Muted autoplay is always allowed.

  2. Autoplay with sound is allowed if:

  • The user has interacted with the domain (click, tap, etc.).
  • On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound.
  1. The user has added the site to their home screen on mobile or installed the PWA on desktop.
  2. Top frames can delegate autoplay permission to their iframes to allow autoplay with sound.

Autoplay example

So with that knowledge an example of a video (your video link is not working anymore) having autoplay could then be to use the embed code and mute it: for example:

https://www.youtube.com/embed/sx_G-J3lOXM?autoplay=1&mute=1

Related