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