简体   繁体   English

在iFrame中使用JavaScript单击表单按钮

[英]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.

相关问题 使用 javascript 选择 iframe 内的单选按钮 - Using javascript to select a radio button inside an iframe 使用JavaScript在iframe中提交表单 - Submitting a form inside an iframe using javascript Javascript:单击div / form内的按钮不执行用于它的JavaScript? - Javascript: Clicking a button inside a div/form not executing the javascript meant for it? 使用jquery或javascript可能会在iframe中单击元素 - Clicking element inside an iframe using jquery or javascript maybe AJAX 如何使用Javascript单击按钮来增加iframe的尺寸? - How to Increase a Iframe's Dimention clicking a Button using Javascript? 单击表单内的按钮后,页面无法在javascript中重定向 - page not redirecting in javascript after clicking a button which is inside a form 如何通过单击按钮显示iframe(JavaScript) - How to display an iframe by clicking a button (JavaScript) JavaScript是否可以通过单击按钮但不使用mailto:或表单操作来发送电子邮件? - Can JavaScript send an email by clicking a button but NOT using mailto: or a form action? 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码 - generating a alphanumeric code using javascript in code generation, by clicking a button in form 单击使用Webdriver和javascript的按钮 - clicking on a button using Webdriver and javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM