0

Is it possible to simulate a click on an embedded YouTube video in an HTML document?

I know a video can be autoplayed with a simple change in the link, but I want to start play by simulating a click from the cursor. It should be registered as a click from the user.

Any help is appreciated.

c.sh
  • 31
  • 7
  • I hope not. Trying to trick a browser into thinking the user clicked something they didn't is bad bad bad (even worse than auto-playing videos). If you want it to autoplay, do it properly and just set the querystring parameter in the embed source – BadFeelingAboutThis Jul 30 '14 at 21:17
  • Is it possible with PHP or any other language? – c.sh Jul 30 '14 at 21:30
  • But I want the click to be registered as user generated. Is it possible with PHP or any other language? Or maybe some a browser extension or automation software? – c.sh Jul 30 '14 at 21:59
  • Not likely - which is as it should be for security reasons. Browser or OS extension possibly (or a custom browser) - at any rate though, this isn't a forum for dodging security measures in browsers. – BadFeelingAboutThis Jul 30 '14 at 22:02
  • depending on why you're trying to register this, you can use Selenium to automate web page interactions on your own machines. – Zombiesplat Jul 31 '14 at 00:35
  • You might also consider trying to click specific x, y cooridnates [http://stackoverflow.com/questions/3277369/how-to-simulate-a-click-by-using-x-y-coordinates-in-javascript](http://stackoverflow.com/questions/3277369/how-to-simulate-a-click-by-using-x-y-coordinates-in-javascript) – Zombiesplat Jul 31 '14 at 00:36

1 Answers1

-1

Jquery has .trigger().

$( "#foo" ).on( "click", function() {
  alert( $( this ).text() );
});
$( "#foo" ).trigger( "click" );
Taz
  • 184
  • 2
  • 7
  • This isn't really relevant to the question asked, as I'm pretty sure the embedded YouTube player doesn't have jQuery click event registered. – BadFeelingAboutThis Jul 30 '14 at 21:20
  • this code isn't working. I gave the iframe id #foo, then tried with object and param format, still no luck. – c.sh Jul 30 '14 at 21:27