Restrict User to access site when Js is disabled in browser.

SurajRane
Posted by in ASP.NET category on for Beginner level | Views : 4234 red flag
Rating: 2.67 out of 5  
 3 vote(s)

In this article I provided some trick for not allowing user to aceess your site when javascript is disabled in browser.


Introduction


In this article I have provided some trick for not allowing user to aceess your site when javascript is disabled in browser. It’s very simple and can be implemented with Html tags <META> and <noscript>. Just like script there is <noscript> tag. This tag runs when there is no script enabled for the browser.

 

Step1

create a page where you want to redirect user when JavaScript is disabled. Say we created a page “noscript.aspx”. See below code:

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<
title></title>
 
<
script type="text/javascript">
   
document.location.href = "Login.aspx";

</
script>

</
head>

<
body>
<
form id="form1" runat="server">
  <
div align="center">    
<
div style="text-align: center; color: Red; font-family: Calibri; font-size: 12pt; width:400px">        
<
b>* JavaScript Need To Be Enabled To visit Requested page.</b>     </div>
</
div>
</
form>
<
/
body>
</
html>

User will land on this page when any page is requested with disabled javascript. Specify , on which page you want to redirect user when javascript is enabled in <script> tag.

Step2

In main master page of your site write <noscript> tag.Specify URL = noscript.aspx page we have created.Meta tag will redirect user to given URL (noscript page in this case) when javascript is disabled.

 

 

<html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">


  <title></title>

</head>
<
body>
<
noscript>          <meta http-equiv="refresh" content="0;URL=noscript.aspx" />
</
noscript>

</
body>
</html>

 

Run the application and test it. :)

Page copy protected against web site content infringement by Copyscape

About the Author

SurajRane
Full Name: Suraj Rane
Member Level: Starter
Member Status: Member
Member Since: 10/8/2009 10:53:40 PM
Country: India

http://www.dotnetfunda.com
System Analyst Suraj Bhaskar Rane

Login to vote for this post.

Comments or Responses

Posted by: Schatak on: 12/4/2010 | Points: 25
nice trick

Login to post response

Comment using Facebook(Author doesn't get notification)