How to check whether the browser supports javascript?
I need to redirect the users to a Notification Page, if the user’s browser don’t support javascript. How can i do this in my asp.net mvc(C#) application?
Whats the best way to handle this in asp.net mvc?
The html i tested:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Stack Overflow</title>
<link rel="stylesheet" href="http://sstatic.net/so/all.css?v=6230">
</head>
<body>
<noscript>
<div id="noscript-warning">Stack Overflow works best with JavaScript enabled<img src="http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" class="dno"></div>
</noscript>
</body>
</html>
Wow at all the -1. Erm, well… it may not be valid, but the
meta-in-noscripthack (as everyone’s already posted and been voted down for) really is the only way to do what you want. But:I think what you want isn’t what you need. No-JS redirection is horrible for usability/accessibility. Please don’t do that.
Consider an approach like SO’s instead: keep the user on the same page, but just include an on-page notification that scripting is unavailable:
You can use CSS to make this big and red and appear on top of the whole of the rest of the page if you have to.
You can be more specific too. Often you need not only JavaScript, but support for certain scripting features that aren’t available everywhere. For example IEMobile (pre-8) does have JavaScript, but has stunted DOM support which stops you running most modern scripts. Or you might be relying on HTML5-related interfaces that aren’t everywhere yet. In that case you can sniff client-side and set the notification’s visibility manually: