【问题标题】:How to automatically click button inside iframe after load加载后如何自动单击iframe内的按钮
【发布时间】:2021-11-09 19:26:48
【问题描述】:

我有一个 iframe,并且在 iframe 的网站内,有一个按钮,我希望在 iframe 加载时自动单击该按钮。这是 HTML 代码。

<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>

【问题讨论】:

  • iframe 是否与主页在同一个域中?如果没有,您将无法访问它。
  • 这能回答你的问题吗? iFrame onload JavaScript event(假设按钮在 iframe 内,如标题所示)
  • 如果按钮不在 iframe 中,您可以使用 iunfixit 提到的 iframe onload 向主窗口发送事件。 stackoverflow.com/questions/9153445/…

标签: javascript html jquery css iframe


【解决方案1】:
 /*   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();

【讨论】:

  • 你能用 HTML 写完整的代码吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-07
  • 2019-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多