Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JavaScript code to simulate a mouse click on an iframe embedded video

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an iframe in a HTML document and need to force or simulate a click on the screen to cause a video to play. Essentially bypassing "autoplay" as that is not working. Tried various ways in JavaScript but not working.

HTML code for autoplay of iframe.

Just need for it to click on the page anywhere after a quick delay for page to load.
 
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Retrieve the DOM object and call .click() on it.  Here is some example code.  Sometimes you might have issues with how the event is propagated, but try this first and see how it works.

https://www.w3schools.com/jsref/met_html_click.asp

Here is some info on propagation

https://www.sitepoint.com/event-bubbling-javascript/
 
Marshal
Posts: 65053
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I shall move you to our JS forum.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!