0

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:

public 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.

pimvdb
  • 151,816
  • 78
  • 307
  • 352
Sankar M
  • 4,549
  • 12
  • 37
  • 55

2 Answers2

2

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/

pimvdb
  • 151,816
  • 78
  • 307
  • 352
  • lnkbtnView.Attributes.Add("OnClick", "javascript:window.open('demo.aspx?upkey=1&ProdName=aaa')" lnbtnView is a Linkbutton exist in a Gridview ....show i cant maintain a variable popup as you said... – Sankar M Aug 01 '11 at 13:42
0

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>
Mehmet Osmanoglu
  • 1,212
  • 15
  • 22