okey_on
okey_on

Reputation: 3006

Make Javascript a requirement

Is there a way to make Javascript a requirement to run pages on a website? such that if the user disables javascript, then he cannot proceed further? For example: I have a PHP site and would want to validate user-inputs with javascript only.

I apologise if this a trivial issue. I am quite new to javascript and i have never seen nor heard of such implementation, but it is solution i would love to know how to implement. Thanks.

Upvotes: 1

Views: 272

Answers (4)

jasonscript
jasonscript

Reputation: 6170

Can you use the NoScript tag?

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript

Upvotes: 1

Aravind.HU
Aravind.HU

Reputation: 9472

The <noscript> tag defines an alternate content for users that have disabled scripts in their browser or have a browser that doesn’t support script.

The element can be used in both and .

You can do some thing like this below and redirect the users to some page saying please enable java script and try again by placing this below code in head tags

<noscript>
  <META HTTP-EQUIV="Refresh" CONTENT="0;URL=showamessagewithjavascriptdisabled.html">
</noscript>

The above code in header will cause a refresh to URL specified if javascript is disabled

Upvotes: 5

Ahmad Azizov
Ahmad Azizov

Reputation: 166

u can technically do that. I am guessing you can set up a cookie in js as soon as the page loads. And then check with php. If it exists, then js works, if not js is disabled. But don't forget that the user can change the cookie name/value manually. It is the same with every other client side control

Upvotes: 0

HMR
HMR

Reputation: 39280

I have a PHP site and would want to validate user-inputs with javascript only.

That is a realy bad idea, users can submit whatever evil data they want creating a html form and post it to your php files.

If you turn off JavaScript and watch this site you will see that some of the functions will work and some don't. You can display a message using the following code:

<div id="jsMessage">Please turn on JavaScript</div>
<script>document.getElementById("jsMessage").style.display="none";</script>

Upvotes: 3

Related Questions