Clicking into iframe

Can you make a page automatically click into an iframe?

I have an iframe showing a game of tetris from another html document and I want it to automatically let me control the pieces when I click a button to make it appear on the page.

Here is some code:

<iframe id="tetrislauncher" src="src/tetris/index.html"></iframe>

<style>#tetrislauncher{display:none;}</style>

<button onclick="$('#tetrislauncher').fadeIn()">Play Tetris</button

I want the button to also do something like

$('#tetrislauncher').click()

but that doesn't work, I'm assuming because you don't click an iframe to call a function like you would in a button.

The point of this is that the game starts automatically, and pauses when you hide the game, but I want to click to make it appear, and be able to access the arrow keys to move the pieces without having to click the iframe beforehand. I'm having the same issue with another iframe playing space invaders, which is made using the same code (basically).

Anybody have any idea how this can be done?

Answers 1

Related Articles