1

hi i have a code that i want to autoplay some youtube videos in any device.the problem is that in mobile devices both android and ios the autoplay events are been disabled. so i want to create a function that will click the iframe. the code i have is the below

<iframe id="text" width="560" height="315" src="https://www.youtube.com/embed/5-RszQzQCvg" frameborder="0" allowfullscreen></iframe>


<form>
  <input type="checkbox" id="myCheck" onmouseover="myFunction()">
</form>

<script>
function myFunction(){
document.getElementById("text").click();}
</script>

the problem is that when i mouseover the checkbox my function dosent work because the video dosent start.

Umesh Aawte
  • 4,590
  • 7
  • 41
  • 51
Agis Soleas
  • 343
  • 1
  • 4
  • 21
  • Check answer here, http://stackoverflow.com/questions/2381572/how-can-i-trigger-a-javascript-event-click – Umesh Aawte May 06 '15 at 15:41
  • i have checked but it is not working either. – Agis Soleas May 06 '15 at 15:47
  • `#text` is the `iframe` element on your main page, it's not the video within the iframe. Clicking on the `iframe` element would be pretty much the same as clicking the frame border. – Teemu May 06 '15 at 15:47
  • is it possible to click the video in the iframe? – Agis Soleas May 06 '15 at 15:48
  • No, it is not possible (cross-domain access is denied). You need [YT JS Player API](https://developers.google.com/youtube/js_api_reference). – Teemu May 06 '15 at 15:50
  • thank you i will give it a try. but will this work on mobile devices? – Agis Soleas May 06 '15 at 15:52
  • It's not possible to autoplay videos on mobile devices. This is by design to protect the users, because videos require high amounts of data which is usually expensive on mobile connections. – xpereta May 12 '15 at 09:18

1 Answers1

0

It's not possible to simulate clicks to simulate videos autoplay in ios devices. Even though you could find a workaround this behavior is by design, so the workaround would likely be fixed.

It is explained in this Apple developer document:

https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html

xpereta
  • 692
  • 9
  • 21