0 Replies - 147 Views - Last Post: 09 May 2012 - 09:28 PM

#1 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 391
  • Joined: 04-January 11

Prevent user from opening multiple instance of a browser page

Posted 09 May 2012 - 09:28 PM

What I want to do is to prevent the user from opening multiple instance of my page.

Let's say I have two pages: Main.aspx and Popup.aspx

On my Main.aspx, I have a button named btnShowPopup. When the user clicks the button, Popup.aspx appears on a new window.

ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "showpopup", "window.open(Popup.aspx','" & GetPopupName() & "','menubar=0,status=0,resizable=1,scrollbars=1,toolbar=0');", True)



The GetPopupName returns a unique ID that is used to name my popup window on load.

My function looks like this:
Private Function GetPopupName() As String
   Session("PopupName") = Guid.NewGuid().ToString().Replace("-", String.Empty)
   Return Session("PopupName")
End Function



Now, when the popup window opens, I have this javascript code to redirect to Invalid.aspx if the window.name does not match the PopupName so as to prevent the user from opening the page by manually typing the URL in the browser's address bar:
<script type="text/javascript">
   if (window.name!="<%= GetPopupName() %>")
   {
      window.open("Invalid.aspx","_self");
   }
</script>



My function, GetPopupName() for this form has this code:
Public Function GetPopupName() As String
   If Not Session("PopupName") Is Nothing Then
      Return Session("PopupName")
   Else
      Return "Invalid"
   End If
End Function



Now, I am successful at allowing the user to open the page in a popup window via the button, btnShowPopup, and at preventing the user from opening the page via typing the URL manually. But what I want to do is to prevent the user from opening the popup again if the popup is already opened.

With my current codes, if I click btnShowPopup, a new window with Popup.aspx opens. If I click it again, it opens again.

I want to have a behavior just like in windows when the form is prevented to have multiple instances open.

Does anyone know of a way to achieve this?

This post has been edited by November-06: 09 May 2012 - 09:30 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1