views:

16

answers:

2

jsFiddle

I have a DailyMotion video embedded in my page, through an iFrame, within a div. If the user clicks on the video, it starts playing.

Is there a way to use jQuery to simulate the user clicking on the video, so that it will start playing automatically? From what I've read so far you can only use jQuery's click() with events attached with jQuery, which wouldn't work here. Can this be done? Thanks for reading.

EDIT: Forgot to mention, I know you can add ?autoPlay=1 to the DailyMotion embed url, but I need to do this for several online video sites, some of which don't support autoplay, so I need to figure out if there's another way to do it.

+2  A: 

In this case there's no need for jQuery at all, you can just add ?autoPlay=1 to the URL, here's your fiddle updated with the change.

Nick Craver
@Nick Craver: Thanks for your answer. I should have been more specific, I'm actually wanting to use this code for several online video sites, some of which don't support autoplay.
ben
@ben - In that case no, there's not really a way to do this with flash...you'll have to call the play method on each, that is *if* they even have a JavaScript API. The same-origin policy will also prevent this in an `<iframe>` from a different domain as well...so you're better off embedding the videos directly, without the use of an `<iframe>`.
Nick Craver
+1  A: 

No, you can't fake interaction with a document in an iframe from another domain, jQuery or otherwise. It would be a pretty serious security hole if you could frame a third-party site (eg that the user happened to be logged into) and started operating it on their behalf.

bobince
@bobince: Damn, thought that would be the case. Thanks for your help.
ben