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>
3
  • 2
    Is the iframe in the same domain as the main page? If not, you can't access it. Commented Sep 14, 2021 at 15:37
  • Does this answer your question? iFrame onload JavaScript event (assuming the button is inside the iframe as title suggests) Commented Sep 14, 2021 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. stackoverflow.com/questions/9153445/… Commented Sep 14, 2021 at 15:51

1 Answer 1

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();
Sign up to request clarification or add additional context in comments.

1 Comment

Can you also write me the full code with the HTML?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.