Using javascript to click an embedded youtube video

533 Views Asked by At

I'd like to click on an embedded youtube video using javascript (so the video plays automatically). I successfully simulated a click on a <div> like this:

function f(){
    alert("hello");
}

<div id="someid" onmouseup="f();">
    my text
</d>

document.getElementById("someid").onmouseup();

How can the above code be adapted to work with an embedded youtube video?

2

There are 2 best solutions below

0
Alex On BEST ANSWER

Just add &autoplay=1 to the link of the video in the <embed> tag.

0
Johnny B. On

If he does what you suggest the views on the embedded video won't count. I'm pretty sure he is asking his question because he is trying to find a way to get the video to autoplay and have youtube count the views at the same time.