Reputation: 15867
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.
Upvotes: 0
Views: 7007
Reputation: 34149
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.
Upvotes: 4
Reputation: 8805
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:
Upvotes: 5
Reputation: 389
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.
Upvotes: 0
Reputation: 3231
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.
Upvotes: 1
Reputation: 78520
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.
Upvotes: 1