0

We have WCAG standard means site should run without javascript.

http://www.w3.org/TR/WCAG/

Is it possible to check WCAG is enabled or not in PHP?

When javascript is disabled :- I have set some php session variables 
When javascript is enabled  :- I want to reset those php session variables

How can i do that?

Matthieu FAURE
  • 383
  • 3
  • 11
Jackson
  • 1,426
  • 3
  • 27
  • 60

2 Answers2

2

WCAG is a set of guidelines, not simply an on/off switch. It highlights best practices to ensure that your site is accessible to people with disabilities can use it. At a high level view, the JavaScript requirement is in the standard because back in the day, not many assitive technology devices or programs could interact with JS. So, the user would experience the site if JavaScript was disabled. This is why it is important to have good <noscript> tags for scripted elements versus having rude comments.

Today popular assistive technology can interact with JavaScript fairly well. It all comes down to what you are doing with JavaScript and how you script the actions.

W3C has provided 37 techniques to use for client-side scripting. WebAIM's JavaScript Accessibility article has a lot of information in it.

Ryan B
  • 3,364
  • 21
  • 35
1

If you ask about whether or not it's possible to detect on the server-side if Javascript is enabled, then the answer is: technically no.

As the server process is not within the browser process, there is not way for the server to inspect if a feature or setting in the browser is enabled / exists.

You can however try to mimic that. E.g. scripts are not going to be loaded from the server-side if javascript is disabled (normally). Also you can insert javascript that will do specifically crafted requests to your server so that you know something is disabled.

<noscript><img src="http://example.com/session-trigger-js-disabled.php?.gif" width="0" height="0"></noscript>
<script src="http://example.com/session-trigger-js-enabled.php?.js"></script>

Note: $_SESSION in PHP can be blocking. The <script src="url"> tag is also blocking, so take care that you're not creating "deadlocks" that will decrease the user-experience with your website.


A more lightweight approach might be to set a cookie and change it if javascript is enabled. Cookies can be read out by PHP, their nature is not blocking and you don't need to waste session for that.

hakre
  • 193,403
  • 52
  • 435
  • 836