Introduction
In this article, we will learn how to disable the new window/tab in web applications.
There are two challenges in preventing multiple windows or tab usage in web applications: i.e how can we differentiate among two requests (GET or POST) at the server-side and how we can stop the user from generating a request (GET or POST) from two tabbed/different windows at the client-side.
The solution to the above problems is the use of window.name at the client-side using JavaScript and checking the HTTP Referer header at the server-side.
Step 1: First we create a Homepage.aspx in our website, like this:
- <head runat="server">
- <title>Home - Restrict Multiple Tab</title>
- <script language="javascript" type="text/javascript">
- if(window.name != "<%=GetWindowName()%>")
- {
- window.name = "invalidAccess";
- window.open("InvalidAccess.aspx", "_self");
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h2>Try to Open the Link given below either in new window or tab.</h2><br />
- <img src="image/img1.jpg" alt="Image" align="right" />
- <br />
- <asp:HyperLink ID="hlDemo1" runat="server" NavigateUrl="~/Demo1.aspx">Page 1</asp:HyperLink>
- <asp:HyperLink ID="hlDemo2" runat="server" NavigateUrl="~/Demo2.aspx">Page 2</asp:HyperLink>
- <asp:HyperLink ID="hlDemo3" runat="server" NavigateUrl="~/Demo3.aspx">Page 3</asp:HyperLink>
- </div>
- </form>
The output of this page looks like this

- <head runat="server">
- <title>Demo 1</title>
- <script language="javascript" type="text/javascript">
- if(window.name != "<%=GetWindowName()%>")
- {
- window.name = "invalidAccess";
- window.open("InvalidAccess.aspx", "_self");
- }
- </script>
- </head>
- <body bgcolor="green">
- <form id="form1" runat="server" >
- <div>
- <h1> Page 1 </h1>
- Try to Open the Link given below either in new window or tab.<br />
- <img src="image/img.jpg" alt="Image" align="right" />
- <br />
- <asp:HyperLink ID="hlDemo1" runat="server" NavigateUrl="~/Demo1.aspx">Page 1</asp:HyperLink>
- <asp:HyperLink ID="hlDemo2" runat="server" NavigateUrl="~/Demo2.aspx">Page 2</asp:HyperLink>
- <asp:HyperLink ID="hlDemo3" runat="server" NavigateUrl="~/Demo3.aspx">Page 3</asp:HyperLink>
- </div>
- </form>
The output of this page looks like this

- <head runat="server">
- <title>Demo 2</title>
- <script language="javascript" type="text/javascript">
- if(window.name != "<%=GetWindowName()%>")
- {
- window.name = "invalidAccess";
- window.open("InvalidAccess.aspx", "_self");
- }
- </script>
- </head>
- <body bgcolor="lime">
- <form id="form1" runat="server">
- <div>
- <h1>Page 2</h1>
- Try to Open the Link given below either in new window or tab.<br />
- <img src="image/img.jpg" alt="Image" align="right" />
- <br />
- <asp:HyperLink ID="hlDemo1" runat="server" NavigateUrl="~/Demo1.aspx">Page 1</asp:HyperLink>
- <asp:HyperLink ID="hlDemo2" runat="server" NavigateUrl="~/Demo2.aspx">Page 2</asp:HyperLink>
- <asp:HyperLink ID="hlDemo3" runat="server" NavigateUrl="~/Demo3.aspx">Page 3</asp:HyperLink>
- </div>
- </form>
- </body>




Balakrishna reddyPosted May 15, 2019, 9:09 AM
Can you place the total solution.
Balakrishna reddyPosted May 15, 2019, 9:09 AM
Where to put GetWindowName() method?.
senthil kPosted Sep 6, 2016, 8:07 AM
Please Provide GetWindowName() method definition.
vinod sainiPosted Sep 10, 2015, 11:41 PM
Incomplete article ... GetWindowName() not found . . . ???
Aamir HussainPosted Aug 25, 2015, 2:10 AM
GetWindowName() not found . . . Please complete article...
vaibhav parmarPosted May 14, 2015, 7:07 AM
I haven't found any method with the GetWindowName(),I think you missed it or forget to include in the blog.Please response.
Suthish NaireditedPosted Oct 31, 2012, 6:05 PMEdited Oct 31, 2012, 6:09 PM
what is GetWindowName() method, where you creating this method.? And where you defining the Window Name, this article is not complete...