4

I've been looking for a way to test to see if the user has Javascript enabled or a browser that supports it in ASP.NET MVC, and if they don't then route them to a page that tells them the site requires it to work.

However I haven't been able to find a definative answer to this..any suggestions?

5 Answers 5

7

I have been searching for the best ways to do this tonight as well and came across, I think, an ingenious solution.

<noscript>
  <meta http-equiv="refresh" content="0;URL=http://yoursite.com/noJavascript" />
</noscript>

This redirects to another page if javascript is disabled without having to call functions, hide/show divs and worry about the flash of the DOM updating.

I know this has already been answered, but I haven't seen this approach anywhere on SO. If there is a reason, someone let me know :)

Sign up to request clarification or add additional context in comments.

Comments

3

You can use the <noscript> element. http://www.w3schools.com/TAGS/tag_noscript.asp. This wouldn't redirect them to another page, but you could put a link they can click on to go to another page.

Comments

1
function isJavaScriptEnabled() {
    return true;
}

I'm actually semi-serious about this. You can use this to check if JS is enabled and cache the result in a session.

the <noscript> option seems to be the most applicable.

what you should strive to do is to make your site completely accessible without javascript enabled and then progressively enhance the site with javascript.

Comments

1

You can use html tag to display a message in browser, when JavaScript is disabled.

<noscript>Your browser has disabled JavaScript.</noscript>

Comments

0

You can check the browser capabilities, which is part of HttpRequestBase, which is part of the httpcontextbase; however, this isn't definitive and the best way to ensure your app works when JavaScript doesn't is to setup your app using an unobtrusive javascript approach.

This ensures that your app works like it would any server-side app, then you use JavaScript to take over links, button clicks, etc. to enable the client-side AJAX features.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.