Tuesday, December 1, 2009

Identifying if a page is called from a popup

I need to identify whether a page has been redirected from a popup window or it has been redirected from a full page, in order for me to perform a Redirect to "Main Menu" or "Close" from a button.

1. Create two buttons (one that performs a PostBackUrl="/") and another one that executes (window.close() javascript event)

1 <asp:Button ID="cmdBackToMenu" runat="server" PostBackUrl="/" Text="Back to Main Menu" />
2 <asp:Button ID="cmdClose" runat="server" Text="Close" OnClientClick="window.close();"/>

2. Create a javascript event that will be called in the form.onload event.

1 <body bgcolor="#CCCCCC" onload="SettingButton();">

3. The javascript event should be able to identify whether a page was redirected from a popup window or from a full page and depending on the situation make visible or invisible the buttons created in the first step.

1 function SettingButton() {
3 if (opener) {
4 document.form1.cmdClose.style.visibility = "visible";
5 document.form1.cmdBackToMenu.style.visibility = "hidden";
6 }
7 else {
8 document.form1.cmdClose.style.visibility = "hidden";
9 document.form1.cmdBackToMenu.style.visibility = "visible";
10 }
11 }

No comments:

Post a Comment