[英]Clicking Form Button using JavaScript inside an iFrame
I have this form inside test.html file 我在test.html文件中有此表单
<form name="myForm1" id="myForm1" action="" method="post" onsubmit="">
<input type="submit" value="YES" class="buttonclass">
</form>
I load it using another file called iframe.html 我使用另一个名为iframe.html的文件加载它
<iframe id="iframeID" src= "test.html"></iframe>
Now how can I automate the click of the submit button in the iframe using JavaScript ? 现在如何使用JavaScript在iframe中自动单击“提交”按钮?
document.querySelector('#iframeID').contentWindow
.document.querySelector('#myForm1').submit();
From an old project.... 来自一个旧项目...
Put this in your iframe code (test.html): 将其放入您的iframe代码(test.html):
function getElement(id) {
return document.getElementById(id);
}
then access the element via 然后通过访问元素
var el = document.getElementById("iframeID").contentWindow.getElement(id);
You should be able to act on that element from there. 您应该可以从那里对该元素进行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.