单击iframe按钮时关闭父窗口
Close parent window on iframe button click
我有一个没有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();
}
};
但它不会被触发。
$('iframe').contents().find('body button').click(function (event) {
event.preventDefault();
$('iframe').remove();
});
如果您想在
单击提交按钮后关闭主窗口,那么您可以执行以下操作。
实时预览
链接到在 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");
});
相关文章:
- 防止Iframe窗体在新窗口中打开
- node-webkit-从父窗口捕获iframe鼠标事件
- 如何关闭html中的iframe弹出窗口
- 允许父窗口在其不同域的子iframe上调用函数
- 检查iframe内部的窗口是否已关闭
- 在jQuery中的IFrame中提交表单后刷新父窗口
- 在引导程序弹出窗口中显示iframe
- 可以'iframe的父窗口中发生捕获错误
- 如何在不使用iframe或库的情况下创建剪切显示窗口区域
- 获取相对于窗口的IFRAME位置
- iframe是否可能在没有主窗口帮助的情况下自行调整大小
- 如何在窗口调整大小时调整iframe的大小
- Iframe如何访问chrome扩展中的父窗口
- 从父窗口上的iFrame内容中关闭iFrame
- 关闭iframe中的模式弹出窗口
- 在iframe内的新选项卡/窗口中打开
- 从子项(iframe)检测窗口关闭命令
- `base`tag导致iframe在Internet Explorer中以新窗口的形式打开
- 是否可以打开一个新窗口并将iframe嵌入其中
- IE11 iFrame点击事件弹出以影响窗口