At 6:42 PM +0100 4/27/11, Geoff Lane wrote:
However, I do have one residual question. I suspect the short answer
to this is "No", but since the list is quiet I'll ask anyway:

Q: Is it possible to check whether Javascript is available on the
client without using client-side Javascript to create a form and hence
pass a variable that will only be set if Javascript is available on
the client? Is there something in $_SERVER etc. that can provide this


To answer your question in a new thread.

No, the $_SERVER super-global isn't going to give you anything nor is anything else like it.

You see, PHP has a difficult time detecting IF Javascript is turned ON in the client's browser because PHP is history by the time the browser does anything, including running Javascript.

As Yogi Berra once said; "It's always hard to predict things especially when it deals with the future."

However, there are two ways to "kind-of" doing it:

Way 1 -- I place an element in html that is hidden from the user's view via css (display:none) and if Javascript is ON then Javascript changes the css so that the element is shown to the user (display:block). Here's an example:

Try clicking "MORE"

That way Javascript routines are shown to the user only if the user's browser is capable of running Javascript. If Javascript is OFF then nothing happens.

Way 3 -- another way is to use unobtrusive Javascript -- here's an example I did for my students:

If Javascript is OFF, then the "Add Another Record" button is not seen by the user -- because it's not in the html.

However, if JavaScript is turned on, then the "Add Another Record" button is shown and becomes available as another option via DOM scripting. That's called unobtrusive Javascript.

Try it!

Now that doesn't mean that JavaScript can't call PHP, because it can -- look here:

and here:

Those are examples of JavaScript running PHP scripts.

So, the world of mixing JavaScript and PHP is quite vast, but you have to know what run's what and when.




PHP General Mailing List (
To unsubscribe, visit:

Reply via email to