This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes detect if javascript is enabled/disabled Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "detect if javascript is enabled/disabled" Watch "detect if javascript is enabled/disabled" New topic

detect if javascript is enabled/disabled

Antonio Giovanni
Ranch Hand

Joined: Jun 27, 2005
Posts: 85
Hi all,

Is there a way on the java server side to detect, if the javascript is enabled or disabled on the client m/c..

It would be great if somebody can give an example code..
i appreciate your help
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42375
A rough outline would go like this:
1) Open a session on the first page you serve
2) in that page, include JavaScript code that will hit a particular URL. This needs to happen w/o the user doing anything, e.g. disguise it as an image URL.
3) in that URL, include a parameter that uniquely identifies the session from which the page was served
4) once that URL is requested, make a note in the session that JS is enabled

Ping & DNS - my free Android networking tools app
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12809
If your entry page has a form, use a hidden variable in the form and have an onload javascript write a different value into the variable.
Antonio Giovanni
Ranch Hand

Joined: Jun 27, 2005
Posts: 85
Hi William ,

Thanks a lot,.. That is working cool..
I agree. Here's the link:
subject: detect if javascript is enabled/disabled