0

I want to click automatically button1, which is in iframe which is on my website. scheme

iframe source: ...<button class="button1">...

I can click it automatically using document.querySelector('.button1').click(); but only on frame source page.

My website has <iframe id="frame1" src="iframe source">

How to click it automatically from my page?

Community
  • 1
  • 1
W.Dud
  • 3
  • 1
  • 5
  • I was thinking about this: `document.getElementById('frame1').contentWindow.querySelector('.button1').click();` but it doesn't work – W.Dud Nov 01 '16 at 17:36

2 Answers2

0

The proper way if through sending a message to the iframe, and on the iframe have an event listener the will fire the click when the message arrives.

here is an Example on iframe communication

Community
  • 1
  • 1
O_Z
  • 1,449
  • 9
  • 10
0
<html>
<body>
<iframe id="test" source="test.html">

</iframe>
</body>
</html>

In scripts:

$('#test').contents().find('BUTTON ID').click(function(){
alert("works")
});
Jays
  • 82
  • 8