It seems to be simple to find but when I searched for this I only found how to enable or disable Javascript on your browser. There are many websites which make it compulsory for Javascript to be enabled and I want to know how. Is there any setting? I want this facility on a website developed using PHP.
-
2Probably the easiest way would be to wrap your content in an element that is hidden and have a message stating JS is required in another element. In the CSS hide the content and show the message so that is the default then in JS switch it. No JS means all they see is a message to enable JS. – Omnikrys Oct 30 '14 at 03:54
-
You know what is weird, when I run an html page with javascript on it, internet explorer ask me if I want to run the script on this page, but when the page has php extension, ie just run the scripts. – Oct 30 '14 at 04:00
-
That is the main purpose of the tag, just put everything you want to be js-only inside it and insert/activate it via js. – technosaurus Oct 30 '14 at 04:01
1 Answers
This question explains some great solutions for checking whether or not JavaScript is enabled.
You can take those answers and try to implement them. You can do what Marc Gear said
There isn't a good way to perform server-side JavaScript detection. Instead, use JavaScript to set a cookie, and then test for that cookie using server-side scripting upon subsequent page views; deliver content appropriately.
However on the first visit there would be no good way to test for Javascript, so you could use the <noscript>
tag to possibly display some alternate text like "Pleas enable JavaScript then reload," though that solution doesn't really let you control whether or not java script is enabled.
In the end, there is no way for you, the server, to enable JavaScript. It is a client-side seting that the user has complete control over. You can only check to see if it is enabled, and if it's not, then encourage the user to enable it.