0

I have an iframe and, inside the website in the iframe, there is a button that I want to be automatically clicked when the iframe load. This is the HTML code.

<div class="buttonnext action-button-container">
        <button type="button" id="nextBtn" class="action-button red0">
          <span id="nextBtn-final">
            CLICK TO PROCEED
          </span>
        </button>
</div>
Gianfiollo
  • 11
  • 2
  • 2
    Is the iframe in the same domain as the main page? If not, you can't access it. – Barmar Sep 14 '21 at 15:37
  • Does this answer your question? [iFrame onload JavaScript event](https://stackoverflow.com/questions/29233928/iframe-onload-javascript-event) (assuming the button is inside the iframe as title suggests) – iunfixit Sep 14 '21 at 15:40
  • If the button is not in the iframe you could send an event to the mainwindow with the iframe onload that iunfixit mentioned. https://stackoverflow.com/questions/9153445/how-to-communicate-between-iframe-and-the-parent-site – Jarne Kompier Sep 14 '21 at 15:51

1 Answers1

0
 /*   You can do it in this way.
    
     1. Get Iframe element
     2. Get the content window object and do a normal dom traversal to your button.
     3. Trigger the event. 
*/    
        var iframe = document.getElementById("iframe");
        var elmnt = iframe.contentWindow.document.getElementsById("nextBtn");
        elmnt.click();
Mr.Throg
  • 925
  • 6
  • 21