views:

1064

answers:

7

Hi, can anyone help me in trying to check whether JavaScript is enabled in client browser using Java code.

Thanks in advance

A: 

A simple thing would be to do a call back from the page, such as an AJAX call. I don't think there's any other way to determine this, at least not universally.

Daniel A. White
A: 

Are you trying to do this server-side or on the client in an applet?

If a browser does not support javascript (or has it turned off), it's highly unlikely they will have support for Java applets.

Ben S
+3  A: 

If a form submit is performed, you can put a hidden input in the form and fill out its value with javascript (from OnSubmit) and check that on the server side.

mitchnull
+6  A: 
John Topley
A: 
function isJavaScriptEnabled(){    return true;    }

Joke ;)

maxp
+2  A: 

In yourform for you can put code like this:

<noscript>
  <input type="hidden" name="JavaScript" value="false" />
</noscript>

The parameter should only be submitted if the browser has scripts turned off. In your Java applications you can check it like so:

boolean javaScript = request.getParameter("JavaScript") == null;
pjesi
I like this idea...but is it a cross-browser solution? It seems like something IE6 would love to mess up.
David Murdoch
Why do you say that? Have you tried it?
pjesi
A: 

If you have PHP support just copy and paste the code below.

<noscript> 
  <input type="hidden" name="JavaScript" value="false" /> 
</noscript> 
/*This code is developed by Lankeshwer(nick name only) and can be used as open source by anyone*/
<?PHP
if($_POST['JavaScript']!='false'){
 echo "<run your javascript code here>";} //replace this line with your actual javascript code
else
 echo "<html><head><meta http-equiv="refresh" content="0;url=www.kharida.com"></head</html>";
?>

wish you a good luck and don't forget to make your code open

Lankeshwer