Hello.
I'm trying to make a javascript that detects if user has Java, on then is he does show one div, e.g. "<div id='error'>" of "<div id='good'>" if he does have Java installed.
Here is the script: - <html>
-
<head>
-
<script type="text/javascript">
-
var test = "Is Java enabled? " + navigator.javaEnabled();
-
var result = test.replace("Is Java enabled? ", "");
-
if (result == "false") {document.getElementById("error").style.display = "";}
-
if (result == "true") {document.getElementById("good").style.display = "";}
-
</script>
-
</head>
-
<body>
-
<div id="error" style="display:none;">
-
<p>Java is NOT installed.</p>
-
</div>
-
<div id="good" style="display:none;">
-
<p>Java is installed.</p>
-
</div>
-
</body>
-
</html>
10 2167
yes, and?
that sure is some complicated code …
Well, this code is not working. Does anyone know why?
have you checked what result contains?
variable result contains "false" or "true". I checked using - document.write("result");
I doubt that. the above code would print "result", not true/false. besides that, while true/false may print as "true"/"false", they do not equal that, i.e. (false == "false") would evaluate as false. simply check with alert((true == "false"));
I've checked it with alert((true == "false")); -> message was false
If I change the script to following, this will work.
Here is the new test code: - <script type="text/javascript">
-
var test = "Is Java enabled? " + navigator.javaEnabled();
-
var result = test.replace("Is Java enabled? ", "");
-
if (result == "true") {document.write("TRUE");}
-
if (result == "false") {document.write("FALSE");}
-
</script>
Does that mean that the problem is in - document.getElementById(div_id).style.display = "";
?
P.S. I've checked it with document.write(result); -> I've mistyped it.
oh, there was a misconception on my side …
anyways, why not doing it the obvious way? - if (navigator.javaEnabled()) {
-
// Java enabled
-
}
-
else {
-
// Java not enabled
-
}
- document.getElementById(div_id).style.display = "";
that resets it to the default value, which I think is the one you give it in the style declaration (which is "none")
it still doesn't work....
comments indeed do nothing …
The problem seems to be that the script was working before the document body was being processed, therefore the call to show the div tags was, essentially ignored because at that stage they were already visible.
I have made a version of your page/script that should work correctly -
<html>
-
<head>
-
<script type="text/javascript">
-
function java_test(){
-
var objTrue = document.getElementById("good");
-
var objFalse = document.getElementById("error");
-
if(navigator.javaEnabled()){
-
objTrue.style.visibility = "visible";
-
}
-
else{
-
objFalse.style.visibility = "visible";
-
}
-
}
-
</script>
-
</head>
-
<body>
-
<div id="error" style="visibility:hidden">
-
<p>Java is NOT installed.</p>
-
</div>
-
<div id="good" style="visibility:hidden">
-
<p>Java is installed.</p>
-
</div>
-
<script type="text/javascript">
-
java_test();
-
</script>
-
</body>
-
</html>
-
This, I believe, is what "Dormilich" meant by the simple way ;)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Web Spinner |
last post by:
I am running Windows 2000 and I can't seem to get my JavaScript
working with ASP. I placed my HTML code in a file called x.asp
under c:\Inetpub\wwwroot, and I placed my JavaScript code in a
file...
|
by: Kamyk |
last post by:
Hello all!
Could you tell me where is the error on the below code, because the script
is sometimes
working correctly and sometimes is not working correctly. I want my new
window with picture...
|
by: web_design |
last post by:
I put this together from some other scripts I am using on a site. I'm
trying to make a better email hiding script. It isn't working. Also, it
causes Internet Explorer 6 SP2 to block the script...
|
by: Manfred Kooistra |
last post by:
I have a problem with some JavaScript code not working. I'm sure I've
done something obviously stupid, but I can't for the live of me figure
it out. Can someone please help?
This is the XHTML...
|
by: redridinghood |
last post by:
Cant understand why my javascript is working in ie6 but not in mozilla.
The javascript that i hav written for validationg my form is below -
<script language="JavaScript"...
|
by: safiratec |
last post by:
Hi,
I want to show a div depending of the value of a <select> option, using 2 functions hidediv() and showdiv() - it is working fine in firefox, but not in IE (tested with IE 6 and 7). <body...
|
by: The1corrupted |
last post by:
I don't know if this is the right forum or not, but right now, my Javascript, that is embedded in PHP, is not working! It works everywhere else but not here. HELP!!
<?php
$soldnumber=$_POST;...
|
by: BillGatesFan |
last post by:
Can someone please tell me why my javascript is producing an error on
the page. It is not working on the following page
http://www.rejoicecenter.org/calendar3.html
Thank you
|
by: nitinsingh1 |
last post by:
Hi,
I am using a PDA containing Windows Mobile 5.0 for my client application in JAVA (JSP & SERVLET).There i am using a dropdown menu on a page.There are 3 different values (A,B,C) in that...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |