3

I am building a html page. I was to make a quick 1 line test which, if the user has javascript enabled says "javascript on" otherwise says "javascript off" just to let them know.

How can I do this?

2 Answers 2

6
<div id="js_onoff">JavaScript off :(</div>
<script>
    document.getElementById("js_onoff").innerHTML = "JavaScript on, yeah! :)";
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

I used this, tested and works in firefox at least. confirmed and thanks.
5
<script type="text/javascript">document.write('JavaScript On');</script>
<noscript>JavaScript Off</noscript>

Maybe?

There are going to be a lot of options here.

4 Comments

noscript elements are ignored by browsers with JavaScript enabled, but blocked (e.g., using an extension like NoScript).
@Marcel: Actually, it appears the (much) earlier releases didn't but they're pretty consistently making that part of their debug efforts (since earlier versions of 2.0.x).
Looks nice, but there are more alternatives to block JavaScript. I fear we can never rely on those elements, how much I'd like them to behave in a consistent, cross-browser manner.
I concur, but it'll never happen. And with all the standards there are for the way CSS/Javascript work and render, I wish they'd all agree on default values/behaviors while they're at it.

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.