Thursday, September 30, 2010

When JavaScript Disabled then redirect noscript page

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.

<h6> Step1</h6>

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.

<h6>Step2</h6>

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. :)

No comments:

Post a Comment