我有一个没有ID的iframe (由第三方生成)。iframe嵌入在登录页面上。当iframe上的提交按钮被点击时,我希望窗口或登录页面被关闭,因为当提交按钮被单击时,它将打开一个新的选项卡。
function() {
    var iframe = document.getElementByTagName('iframe');
    var sbutton = document.getElementById("form_002b_ao_submit_href");
    iframe.sbutton.onclick = function() {
        window.unload();
    }
};但它不会被触发。
发布于 2016-03-03 18:21:45
$('iframe').contents().find('body button').click(function (event) {
    event.preventDefault();
    $('iframe').remove();
});发布于 2016-03-03 18:47:30
如果您想要在单击submit按钮后关闭主窗口,则可以执行以下操作。
Live Preview
Link to the test page that is loaded in the iframe
HTML
<iframe src="http://s.codepen.io/larryjoelane/debug/dMoqPL"></iframe>JavaScript
//select the iframe element without an id
var submitButton = $("iframe").contents().find("#submit_button");
submitButton.on("click", function(event) {
  //if you need to prevent default actions(form submit for example)
  event.preventDefault();
  //close the window
  window.close();
  //debugging only
  //alert("iframe submit button click event fired");
});https://stackoverflow.com/questions/35768884
复制相似问题