Question

Im placing no script tag on my master page that if a user dont have javascript enabled or its browsers doesnt support javascript it redirect to a specific view. im using this code

 <noscript>    
  <% Response.Redirect("../UserLogin/Error");  %>
 </noscript>

but the problem is its redirecting me everytime i open the page although my javascript is enabled. Im using asp.net mvc2 what may be the problem or is there is any other way to do this?

Was it helpful?

Solution

The tag noscript is evaluated in the client (browser). The server doesn't know if client has script support, so every time it redirects.


EDIT

Explain better: the server just creates a string (HTML) and send it to browser. It doesn't parse to see if browser has script support.


EDIT 2

You can use meta refresh tag. See:

<head>
    <noscript>
    <meta http-equiv="refresh" content="0;url=http://example.com/" />
    <!-- Redirect to http://example.com/ immediately -->
    </noscript>
</head>

I tested in firefox and works.

OTHER TIPS

Response.Redirect is executed on the server side and it will send a 302 status code to the browser which will automatically redirect. You probably want:

<noscript>    
    Please enable javascript to use this site.
</noscript>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top