this is my parent page, from where i'm opening a popup
<html xmlns="">
<head id="Head1" runat="server">
<title>Popup example</title>
<script type="text/javascript">
function OpenPop() {
window.scrollTo(0, 0);
var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
var height = document.documentElement.clientHeight + document.documentElement.scrollTop;
var layer = document.createElement("div");
layer.style.zIndex = 2;
layer.id = "layer";
layer.style.position = "absolute";
layer.style.top = "0px";
layer.style.left = "0px";
layer.style.height = document.documentElement.scrollHeight + "px";
layer.style.width = width + "px";
layer.style.backgroundColor = "black";
layer.style.opacity = "0.75";
layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=75)");
document.body.style.position = "static";
document.body.appendChild(layer);
var size = { "height": 220, "width": 400 };
var iframe = document.createElement("iframe");
var popUrl = 'popup.htm';
iframe.name = "Logic Form";
iframe.id = "popup";
iframe.src = popUrl;
iframe.style.height = size.height + "px";
iframe.style.width = size.width + "px";
iframe.style.position = "fixed";
iframe.style.zIndex = 3;
iframe.style.backgroundColor = "white";
iframe.frameborder = "0";
iframe.style.top = ((height + document.documentElement.scrollTop) / 2) - (size.height / 2) + "px";
iframe.style.left = (width / 2) - (size.width / 2) + "px";
document.body.appendChild(iframe);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<a onclick="OpenPop();" href="#">OpenPopup</a>
</div>
</form>
</body>
and this is my popup.html page,
<html xmlns="">
<head>
<title></title>
<script type="text/javascript">
function closeIframe() {
var iframe = opener.document.getElementById("popup");
var layer = opener.document.getElementById("layer");
iframe.parentNode.removeChild(iframe);
layer.parentNode.removeChild(layer);
}
</script>
</head>
<body>
<h3>This is Popup</h3>
<a onclick="closeIframe();" href="#">Close</a>
</body>
</html>
problem : on popup.html , there is close button, who is calling function to remove iframe, but i am not able to close popup, anybody help?
OR anybody have better solution or example to do popup like this?
any help highly appreciated
this is my parent page, from where i'm opening a popup
<html xmlns="http://www.w3/1999/xhtml">
<head id="Head1" runat="server">
<title>Popup example</title>
<script type="text/javascript">
function OpenPop() {
window.scrollTo(0, 0);
var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
var height = document.documentElement.clientHeight + document.documentElement.scrollTop;
var layer = document.createElement("div");
layer.style.zIndex = 2;
layer.id = "layer";
layer.style.position = "absolute";
layer.style.top = "0px";
layer.style.left = "0px";
layer.style.height = document.documentElement.scrollHeight + "px";
layer.style.width = width + "px";
layer.style.backgroundColor = "black";
layer.style.opacity = "0.75";
layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=75)");
document.body.style.position = "static";
document.body.appendChild(layer);
var size = { "height": 220, "width": 400 };
var iframe = document.createElement("iframe");
var popUrl = 'popup.htm';
iframe.name = "Logic Form";
iframe.id = "popup";
iframe.src = popUrl;
iframe.style.height = size.height + "px";
iframe.style.width = size.width + "px";
iframe.style.position = "fixed";
iframe.style.zIndex = 3;
iframe.style.backgroundColor = "white";
iframe.frameborder = "0";
iframe.style.top = ((height + document.documentElement.scrollTop) / 2) - (size.height / 2) + "px";
iframe.style.left = (width / 2) - (size.width / 2) + "px";
document.body.appendChild(iframe);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<a onclick="OpenPop();" href="#">OpenPopup</a>
</div>
</form>
</body>
and this is my popup.html page,
<html xmlns="http://www.w3/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function closeIframe() {
var iframe = opener.document.getElementById("popup");
var layer = opener.document.getElementById("layer");
iframe.parentNode.removeChild(iframe);
layer.parentNode.removeChild(layer);
}
</script>
</head>
<body>
<h3>This is Popup</h3>
<a onclick="closeIframe();" href="#">Close</a>
</body>
</html>
problem : on popup.html , there is close button, who is calling function to remove iframe, but i am not able to close popup, anybody help?
OR anybody have better solution or example to do popup like this?
any help highly appreciated
Share Improve this question edited Sep 12, 2012 at 7:03 Arti Patel asked Sep 12, 2012 at 7:02 Arti PatelArti Patel 3133 gold badges6 silver badges15 bronze badges 1- does your control goes to function closeIframe() function when you click on Close? – Ankit Commented Sep 12, 2012 at 7:06
2 Answers
Reset to default 1Your CloseIframe
method should be:
function closeIframe() {
window.parent.ClosePop();
}
and in your main page, right under OpenPop
method, add the close action, like:
function ClosePop() {
var layer = document.getElementById("layer");
var iframe = document.getElementById("popup");
document.body.removeChild(layer); // remove layer
document.body.removeChild(iframe); // remove div
}
You can use jQuery UI dialog box for showing modal popup window. It will be easy to handle.
Also there are lots of jQuery plugins available for showing popup like fancy box, color box, etc