Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing for Javascript is enabled in ASP.NET MVC

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?

like image 238
dswatik Avatar asked Dec 22 '22 05:12

dswatik


1 Answers

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

like image 156
Tommy Avatar answered Feb 02 '23 09:02

Tommy