How to close a popup window in a parent window?
I need to close a popup window which has been loaded by a parent window.
This popup window is a Documentviewer
window in my webapp.
I need to close this viewer by clicking a logout button which is in master page.
My code:
publ开发者_如何学Goic string MySession //server side code
{
get
{
if (Session["RegID"] != null)
{
return Session["RegID"].ToString();
}
else
{
return "";
}
}
}
//client side code
$(window).load(function() {
Start();
});
function Start()
{
timedCount();
var t=setTimeout("Start()",10000);
}
function timedCount()
{
/*var out="<%=Session["RegID"]%>";*/
var out='<%=MySession%>';
if(out!="")
{
alert(out);
}else
{
window.close();
}
}
Server code is executed at very first time only.
My target is to close the popup if it is opened when user logs out.
You probably have something like this on your parent page:
window.open(...);
If you change this to:
var popup = window.open(...);
then at any time you can close it by coding:
popup.close();
http://jsfiddle.net/pimvdb/bjkNx/1/
Put your popup window in global variable:
<script>
var popupWindow;
function openw(url) {
popupWindow = window.open(url, "popup", "");
}
function closew() {
if (popupWindow) {
popupWindow.close();
}
}
</script>
<a href="javascript:openw('about:blank')">open</a><br />
<a href="javascript:closew()">close</a>
精彩评论