[英]Trigger a button click from the parent that exists within an Iframe
我在iframe中具有以下按钮的路径,即:
div.iframe-container > iframe#builder-frame > html > body > div#header > ul.header-toolbar.hide > li > span.deploy-button-group.button-group > a#btn-deploy.deploy-button
使用上述路径,我尝试使用jQuery转到a#btn-deploy.deploy-button
,以便在iframe中触发对此按钮的click事件。
我不确定如何使用jQuery实现此功能,以便在我的JavaScript代码中从父窗口转到此按钮。
我尝试了以下方法,但无济于事:
$('#builder-frame').contents().find('#btn-deploy').trigger("click");
我知道这可能是重复的,但实际上这是我需要协助的进入iframe按钮的路径。
为确保iframe已加载,您应该使用on load
事件。
然后,不必选择按钮,您不必编写整个路径。 特别是当它具有唯一的id
时。
您的代码应类似于:
$("#builder-frame").on("load", function(){ $(this).contents().find('#btn-deploy').trigger("click"); });
我建议使用纯JavaScript。
如果您iframe的ID是#builder-frame,则可以使用:
document.querySelector('#builder-frame').contentWindow.document.querySelector('#btn-deploy').click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.