javascript - Body onLoad 点击刷新iframe

标签 javascript html iframe click onload

我有一个 iframe,其中有一个按钮,我想单击该按钮来加载页面。 iframe 是:

    `<iframe id="rf" onload="myFunction()" style="width: 100%; height: 600px;" src="http://clients.mindbodyonline.com/ws.asp?studioid=103099&amp;stype=-7&amp;sTG=22&amp;sView=day" width="320" height="240" frameborder="0" scrolling="auto"></iframe>`

我在其下方添加了此 JavaScript 以单击页面加载按钮,但它不起作用。 “tabA7”是按钮 ID。

    `<script>
    function myFunction{
    document.getElementById("tabA7").click(); 
    }
    </script>`

最佳答案

您的代码没有任何问题(请参阅实际代码的代码片段)。它可能不执行单击事件的唯一原因是因为没有 ID 为 tabA7 的元素。

function myFunction() {
  document.getElementById('theButton').click();
}

function button() {
  alert('button clicked');
}
<iframe id="rf" onload="myFunction()" style="width: 100%; height: 600px;" src="http://clients.mindbodyonline.com/ws.asp?studioid=103099&amp;stype=-7&amp;sTG=22&amp;sView=day" width="320" height="240" frameborder="0" scrolling="auto"></iframe>
<br/>
<button id="theButton" onclick="button()">button</button>

关于javascript - Body onLoad 点击刷新iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37336091/

相关文章:

javascript - 在表单验证函数中查找类

php - 如何嵌入谷歌iframe?

javascript - Three.js - 释放内存

javascript - 无法在 Cordova iOS 应用程序中添加自动完成功能

html - 在内部元素中使用带填充的 Flexbox

css - 谷歌翻译下拉窗口不会在较小的屏幕上调整大小

javascript - 使用 Nightwatch 访问 iFrame 元素

javascript - 带有 Angular js 的 Jquery slider 无法正常工作

javascript - JavaScript 中 "intersect"两个 JSON 对象数组的公共(public)属性的最佳方法?

html - 为什么以百分比表示的图像宽度也会影响图像高度?