Simulate real mouse click

前端 未结 2 1067
挽巷
挽巷 2021-02-19 12:02

What I want to do is execute a mouse click say on youtube to press play when the page loads. How do I click that specific location (assuming it is always in the same location)?<

2条回答
  •  迷失自我
    2021-02-19 12:24

    
    


    document.getElementById("myButton").click();
    

    http://fiddle.jshell.net/Shaz/HgyeZ/

    That's with regular clickable items though. But with YouTube Videos, you could also append &autoplay=1 to the end of the url (if it's embedded into a page).

    http://fiddle.jshell.net/Shaz/tcMCa/

提交回复
热议问题