-1

I have used some javascript codes in a mini website that I have designed.One of them is click on an image and the image changes. But this wouldn't work if a person who is visiting has disabled javascript in the browser settings. How do I check if the javascript is disabled? And how do I display a message saying enable javascript since this cannot be done using alert function?

It would be better if the explanation is based on php! Please help me!

Calimero
  • 4,238
  • 1
  • 23
  • 34
Mathews Mathai
  • 1,707
  • 13
  • 31
  • As an aside, if you've got something server side that might require JavaScript to be enabled on the client (e.g. Ajax) you can use JavaScript to inform the server that it's running by using it to set a cookie (`document.cookie` : https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie) - if that cookie doesn't exist on subsequent requests (obviously the server won't know first time around) you can assume that JS isn't enabled on the client. – CD001 Nov 26 '15 at 16:39

3 Answers3

4

Using the noscript element :

<script type="text/javascript">
    document.write("Hello World!")
</script>
<noscript>Your browser does not support JavaScript!</noscript>
Calimero
  • 4,238
  • 1
  • 23
  • 34
2

Use a noscript tag:

<noscript>Javascript required</noscript>
Steve
  • 20,703
  • 5
  • 41
  • 67
1

Just use

<script>alert("Hello WOrld");</script>

and when you run the html page there should be a popup box that says "Hello World". That's how you will know if your javascript is working.

  • How will this script run if the user has disabled javascript? Basically,this script you have provided is javascript and this wouldn't be excuted! Am I right? – Mathews Mathai Nov 26 '15 at 16:47