<p>I assume that you can't use a JavaScript code snippet to validate if the browser user has turned off JavaScript. So what can I use instead? Can someone offer a code sample?</p>

<p>I'm looking to wrap an if/then statement around it.</p>

<p>I often code in CFML, if that helps.</p>

[{'answer_id': 45102, 'author': 'Daniel Jennings', 'author_id': 3641, 'author_profile': 'https://Stackoverflow.com/users/3641', 'pm_score': 3, 'selected': False, 'text': '<p>Use the &lt;noscript&gt; HTML tags.</p>\n'}, {'answer_id': 45104, 'author': 'Chris Marasti-Georg', 'author_id': 96, 'author_profile': 'https://Stackoverflow.com/users/96', 'pm_score': 1, 'selected': False, 'text': '<pre><code>&lt;noscript&gt;\n    ...some non-js code\n&lt;/noscript&gt;\n</code></pre>\n'}, {'answer_id': 45105, 'author': 'Kyle Cronin', 'author_id': 658, 'author_profile': 'https://Stackoverflow.com/users/658', 'pm_score': 0, 'selected': False, 'text': "<p>You might have javascript execute some AJAX query and check to see if it has. Those that download the page and don't execute the query either have JS disabled or they're robots.</p>\n"}, {'answer_id': 45109, 'author': 'Matt Mitchell', 'author_id': 364, 'author_profile': 'https://Stackoverflow.com/users/364', 'pm_score': 2, 'selected': False, 'text': "<p>He's asking for a check to see if javascript is enabled.\nI can only think of doing exactly what the OP said - try using some Javascript with an interval to send a callback if JS is activated - unfortunately I don't think you can check server side whether JS is enabled which is why you use  tags rather than render different content from the server.</p>\n"}, {'answer_id': 45112, 'author': 'Daniel Huckstep', 'author_id': 4657, 'author_profile': 'https://Stackoverflow.com/users/4657', 'pm_score': 0, 'selected': False, 'text': '<p>Really all you can do is put some message in the  tags. I seem to remember trying this on ASP.NET somewhere, but you can really only tell if the browser supports Javascript, not whether or not it is actually allowed/enabled.</p>\n'}, {'answer_id': 45113, 'author': 'EndangeredMassa', 'author_id': 106, 'author_profile': 'https://Stackoverflow.com/users/106', 'pm_score': 0, 'selected': False, 'text': "<p>I don't know much about CFML, but .NET has the ability to detect browser capabilities. It does not, however, have the ability to detect if the browser is <strong>capable</strong> of javascript, but has it turned <strong>off</strong>. So, you're stuck there too.</p>\n\n<p>Besides the HTML noscript tag, there's not much you can do, as far as I know, besides writing javascript progressively (see progressive enhancement) so that you don't need to check for Javascript:off.</p>\n"}, {'answer_id': 45115, 'author': 'Timbo', 'author_id': 4310, 'author_profile': 'https://Stackoverflow.com/users/4310', 'pm_score': 3, 'selected': False, 'text': "<p>Not sure what you are trying to do but if you just need to inform the user that Javascript is required you can just use the '&lt;noscript&gt;' tag.  If you need to know on the server you could make an Ajax style request to the server from javascript.  If you get the request javascript is working otherwise its not.</p>\n"}, {'answer_id': 45116, 'author': 'Kyle Cronin', 'author_id': 658, 'author_profile': 'https://Stackoverflow.com/users/658', 'pm_score': 0, 'selected': False, 'text': "<p>I don't know JS, but would it be possible to modify the links inside the page with JS? If someone goes to the unmodified link, they're not using JS, but if they do then they are using JS. Does this make any sense?</p>\n"}, {'answer_id': 45133, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': True, 'text': '<p>Are we talking about something like this:</p>\n\n<p>JavaScript:</p>\n\n<pre><code>&lt;body&gt;\n...\n...\n&lt;script type="text/javascript"&gt;\n&lt;!--\ndocument.write("Hello World!")\n//--&gt;\n&lt;/script&gt;\n&lt;noscript&gt;Your browser does not support JavaScript!&lt;/noscript&gt;\n...\n...\n&lt;/body&gt;\n</code></pre>\n'}, {'answer_id': 45156, 'author': 'seanb', 'author_id': 3354, 'author_profile': 'https://Stackoverflow.com/users/3354', 'pm_score': 0, 'selected': False, 'text': "<p>Have never worked out how to do it without a round trip, so it depends on what your goal is.  </p>\n\n<p>If they have to have javascript to proceed, then I have (in .net) done things like disabling the login button at the server side, then enabled it client side it with javascript, and used a noscript tag to show an error message.</p>\n\n<p>If it has to work either way, you can use progressive enhancement, and / or use js to set a hidden field and then set a session variable, but this means that you don't know until they get to the second request.</p>\n"}, {'answer_id': 45158, 'author': 'Jared', 'author_id': 1980, 'author_profile': 'https://Stackoverflow.com/users/1980', 'pm_score': 3, 'selected': False, 'text': '<p>this is a total hack but you could use an iframe inside the noscript tag to trigger an HTTP GET on a url to tell the server that a user doesn\'t have javascript enabled.</p>\n\n<pre><code>&lt;body&gt;\n...\n...\n&lt;noscript&gt;\n    &lt;iframe src ="/nojs.aspx?SOMEIDENTIFIER=XXXX&amp;NOJS=TRUE" style="display: none;"&gt;\n    &lt;/iframe&gt;\n&lt;/noscript&gt;\n...\n...\n&lt;/body&gt;\n</code></pre>\n'}, {'answer_id': 45357, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Yes that NoScript snippet is right.</p>\n'}, {'answer_id': 45425, 'author': 'Ian Oxley', 'author_id': 1904, 'author_profile': 'https://Stackoverflow.com/users/1904', 'pm_score': 2, 'selected': False, 'text': '<p>If you use <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript" rel="nofollow noreferrer">Unobtrusive JavaScript</a> then you don\'t need to check whether the user has JavaScript enabled.</p>\n\n<p>If they have got JavaScript enabled then they\'ll get the full effect, but if they haven\'t then users will still be able to use your site. And as well as being better for accessibility you might find this approach boosts your SEO.</p>\n'}, {'answer_id': 45436, 'author': 'abigblackman', 'author_id': 2279, 'author_profile': 'https://Stackoverflow.com/users/2279', 'pm_score': 0, 'selected': False, 'text': '<p>you could write</p>\n\n<pre><code>&lt;script type="text/javascript" language="javascript"&gt;document.write("&lt;input type=\'hidden\' name=\'hasJs\' value=\'1\' /&gt;");\n</code></pre>\n\n<p>or otherwise write a cookie via js and then read it at the server if you want to check server side for js. </p>\n'}, {'answer_id': 23997329, 'author': 'Amanuel Nega', 'author_id': 2711378, 'author_profile': 'https://Stackoverflow.com/users/2711378', 'pm_score': 0, 'selected': False, 'text': "<p>if you are looking for a way to check it server side, you're can send the user a js that puts a cookie.... if the cookie exist on a a request then you can tell if the scripted worked or not!</p>\n"}, {'answer_id': 28679233, 'author': 'lilHar', 'author_id': 984415, 'author_profile': 'https://Stackoverflow.com/users/984415', 'pm_score': 0, 'selected': False, 'text': "<p>One reliable way to do this is using javascript's $.post to send a note to your server. (Apologies if there's any errors in this, written off top of my head, will update later when I get around to testing). Should allow you to build it so you can even pull from session data if they're using javascript, which will allow you to serve up replacements for javascript without having to resort to . </p>\n\n<p>Your on-page script:</p>\n\n<pre><code>&lt;script&gt;\nfunction myJavascriptTest(){\n    $.post ()('myJavascriptTest.php', {myJavascriptOn: true}, function(){\n    return true;\n}\nmyJavascriptTest()\n&lt;/script&gt;\n</code></pre>\n\n<p>And in the targeted .php...</p>\n\n<pre><code>&lt;?php\n\nif ($_POST['myJavascriptOn'] == true){\n    $_SESSION['javascriptIsOn'] = true;\n} else {\n    $_SESSION['javascriptIsOn'] = false;\n}\n?&gt;\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/45097', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']