0

Is there any way possible to detect if a user has disabled JavaScript after load of the page so that <noscript> tags are rendered? Server side or client side is fine.

5
  • 2
    possible duplicate of How to detect if JavaScript is disabled? Commented Jul 26, 2011 at 18:20
  • Afaik it's not possible. Commented Jul 26, 2011 at 18:22
  • @marc Please note how I said after the page has loaded. The post you linked to only works on load of the page. Commented Jul 26, 2011 at 18:22
  • Can you explain more about what you are trying to achieve? Commented Jul 26, 2011 at 18:24
  • why should someone disable javascript globally? google also just works with javascript. you should also create a version that works without javascript and tell on this site the visitor, he should activate javascript Commented Jul 26, 2011 at 18:33

5 Answers 5

5

You could try putting an image inside the <noscript> tag, which would point to a php file of yours, which in turn it should return an image. This could allow you to know in the server that the user has Javascript disabled.

How to identify the user: you could rely on the session, or set an ID to the url of the image.

You could use the answer on this question as an example on how to server image files from a php script where you could add your logic to detect if the user has js disabled:

Return a PHP page as an image

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

Comments

4

Here is an idea I got from a book long time ago

<script>
document.cookie= "js_enabled=true";
</script>

Use the above on some first page that you see. Then check for that cookie on the next request to see if javascript is enabled. Of course this has the same flaw if cookies are disabled.

Comments

1

no... any kind of such detection after the page is loaded would have to be detected with js, and if it's disabled, it can't even do anything if it is.

Comments

1

Why not just render the NOSCRIPT tags all the time? That's the point of that tag, to provide content when JS is disabled. If the user is seeing what's in the NOSCRIPT's then they clearly don't have JavaScript enabled.

You could also have a JavaScript AJAX call fire at page load. If your server recieves a request for the page, but then does not receive the AJAX call by the client within the standard loading time frame, then the server can assume the client doesn't accept JS. Not perfect mind you, but you are dealing with client-side JS here.

1 Comment

I like this idea, but might be difficult to tell whether JavaScript was in fact turned off or the page was just closed.
0

I don't think there is really a good way to do server-side JS detection. <noscript> is the semantic way to specify non-javascript content - so I suppose rather then detect if JS is disabled, you should detect if it is enabled. You can hide the detection by default, and put a <style> block inside the <noscript> to unhide.

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.