父页面和子页面,在父页面中,我在子页面中使用Iframe,我有多个按钮,我想在父页面中编写按钮代码。我不能在子页面上写任何东西。我想在按钮点击时调用window.close。提交数据后。这个按钮可以是批准按钮,拒绝按钮,取消按钮。那么我如何在父页面中调用window.close?
<html>
<head>
<title>Parent Page</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript">
</script>
<script language="javascript" type="text/javascript">
function openpopup() {
var popper = window.open('Child.html', '_blank', 'width=400,height=400');
popper.focus();
}
$(document).ready(function ()
{
$("#youriframeid").contents().find("input[type=button]").on('click', function () { top.window.close(); })
});
</script>
<iframe id="youriframeid" src="child.html" width="200" height="750" style="border: solid 1px #990000;" ></iframe>
</body>
</html>
<html>
<head>
<title>Child page</title>
</head>
<body>
<p>
<input id="child" type="button" value="Close [x]" />
<div>
<table border="1">
<tr>
<td>Name</td>
<td><input type="text" title="Show"/></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" title="Show" /></td>
</tr>
</table>
</div>
</p>
</body>
</html>发布于 2016-05-02 21:52:02
父页面:
<script language="javascript" type="text/javascript">
var popper;
function openpopup() {
popper = window.open('Child.html', '_blank', 'width=400,height=400');
popper.focus();
}
window.CallParent = function () {
popper.close();
}
</script>
<input id="btnopen" type="button" value="Open" onclick="openpopup();" />子页面:
<p>
<input id="child" type="button" value="Close [x]" onclick="opener.CallParent();" />
<div>
<table border="1">
<tr>
<td>Name</td>
<td><input type="text" title="Show"/></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" title="Show" /></td>
</tr>
</table>
</div>
</p>发布于 2016-05-03 15:04:39
<html>
<head>
<title>Parent Page</title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<iframe id="youriframeid" src="child.html" width="400" height="250" style="border: solid 1px #990000;" ></iframe>
<script type="text/javascript">
$('#youriframeid').load(function(){
var iframe = $('#youriframeid').contents();
iframe.find("input[type=button]").click(function(){
alert("0");
});
});
</script>
</body>
</html>https://stackoverflow.com/questions/36983000
复制相似问题