I have developed an ajax application framework using php/jQuery etc. I would like to 'require' a user to have javascript enabled in order use the application (they are all internal apps so we are able to dictate the compatibility).
How can I detect if ja开发者_如何学Pythonvascript is enabled on the serverside? please provide an example.
You can't detect this server-side, you can however present a message client-side with the <noscript>
tag, like this:
<noscript>
<div class="alert">You need to enable JavaScript to use this site.</div>
</noscript>
<noscript>
tags appear when the client doesn't have JavaScript enabled for whatever reason, so use them to present a message, element, etc to them...just give it some styling and you're good to go.
You can't. You will need to run it on the client, then have it either go to a specific URL, or contact the server via AJAX to notify it.
Never done this but consider this webservice scenario, reductio ad absurdum:
- assume that js is disabled and print an non-js content
- register an ajax request just in case js will be active, that will pass a token to a server listener
- if the listener receives a message in resonable timeframe return a new content and change the non-js content with it
This way you are covered for both scenarios. Another approach is the regular one with starts with the assumption that js is enabled. By the way,I guess about 90 % of webuser have js enabled, maybe even more.
Upon some creative thinking... I think I am going to go with this solution - but I'd like feedback.
Set a cookie with JS on page load - detect if its there on the server-side
To me this seems viable because it's super light-weight and it fits my application structure nicely. The idea of straying from my ajax call structure bothers me.
Just do it on the client side. If javascript is on it redirects to good site, else it display simple html page with error message.
精彩评论