0

I have a snippet here that should show weather or not java is enabled. I had it set to run via onclick of a button, but I want to instead use an onload event in a P element to show the results.

the issue I am having is I get no results shown when i have set to an onload event, but it I create a button and use an onclick event it works.

what could be the issue here?

html

<p><strong>Display weather browser has java enabled.</strong></p>
<p id="javaAnswer" onload="checkJava()"></p>

javascript

    function checkJava() {
        var x = "Java Enabled: " + navigator.javaEnabled();
        document.getElementById("javaAnswer").innerHTML = x;
    }

2 Answers 2

4

The onload event in attached to the following tags exclusively: <body>, <frame>, <iframe>, <img>, <input type="image">, <link>, <script>, <style>.

It does not apply for any other tag.

if you insist to execute the script after the <p> element insert a new script tag immediately after the <p> tag.

<script>
    checkJava();
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

This is how you do it.

function checkJava() {
  var x = "Java Enabled: " + navigator.javaEnabled();
  document.getElementById("javaAnswer").innerHTML += x;
}
<body onload="checkJava()">
<p><strong>Display weather browser has java enabled.</strong></p>
<p id="javaAnswer"></p>
</body>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.