Home > Archive > PHP Programming > April 2005 > Using PHP to detect JavaScript support
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using PHP to detect JavaScript support
|
|
| Nicholas Shanks 2005-04-26, 8:57 am |
| I would like to use PHP (or any other server-side technique) to detect
if JavaScript was turned on in the user's browser. Is there any known
way to do this, and if not, why not!
I realise I could serve one page to both, and have the basic function
there by default and use DOM to replace it with another, but it would
be more efficient and lower overhead to serve different pages to
different UAs. Any suggestions welcome.
Now if I was Galactic Overlord, browsers that supported JavaScript
would be required to declare so in the Accept-Content HTTP header they
send.
Since I am not on usenet much, could anyone who replies pleace CC my
email address?
- Nick
| |
| Alvaro G Vicario 2005-04-26, 8:57 am |
| *** Nicholas Shanks wrote/escribió (Tue, 26 Apr 2005 11:56:41 +0100):
> I would like to use PHP (or any other server-side technique) to detect
> if JavaScript was turned on in the user's browser. Is there any known
> way to do this, and if not, why not!
Use an initial test page where JavaScript creates a variable and sends it
to server (hidden form field or URL attribute, cookie...) and read that
value afterwards from PHP. Just be aware that cookies can be disabled and
user may reach your page skipping the inicial test page.
However, I'd say its a thousand times easier to just write code that works
100% in server and use client-side JavaScript for UI enhancements. Why work
twice?
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
| |
| Daniel Tryba 2005-04-26, 8:57 am |
| Nicholas Shanks <contact@nickshanks.com> wrote:
> I would like to use PHP (or any other server-side technique) to detect
> if JavaScript was turned on in the user's browser. Is there any known
> way to do this, and if not, why not!
No, because it is a clientside setting serverside environments don't
know until told (by the client).
> I realise I could serve one page to both
How do you know what page to serve? That is what you are asking!
> and have the basic function there by default and use DOM to replace it
> with another
What DOM (if any)?
> but it would be more efficient and lower overhead to serve different
> pages to different UAs. Any suggestions welcome.
I beg to differ, serverside UA sniffing is almost always very poorly
implemented (take a look at the browsercap function and have a good
laugh). But than again clientside UA sniffing is also faulty in many
cases.
If you really want to server different pages to different available
capabilites there is an easy way to distinguis between js and nojs:
http://tmp.tryba.nl/hasjs/
| |
| frizzle 2005-04-26, 3:58 pm |
| You could use a button/link with a page in the href-part,
and an e.g. onClick="document.location.href='page2.php';return false"
or a document.write etc...
| |
| Colin McKinnon 2005-04-26, 3:58 pm |
| Alvaro G Vicario wrote:
> *** Nicholas Shanks wrote/escribió (Tue, 26 Apr 2005 11:56:41 +0100):
>
> Use an initial test page where JavaScript creates a variable and sends it
<snip>
Wouldn't it be simpler to just start each non-js page with js code to
redirect to the js-enabled version. Point the user towards the non-js entry
points and bingo.
C.
|
|
|
|
|