Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle when javascript is turned off [duplicate]

Possible Duplicate:
How to detect if JavaScript is disabled?

My first web application relies heavily on Javascript and AJAX application.

Other than my Login Page, majority of the pages relies on Javascript and Ajax when submitting data to the server. I have been thinking about this, if user disables his/her javascript then my app does not behave accordingly.

I used this code in my Login page

<NOSCRIPT>
    Javascript is required to run this pages.  Please turn it on or ask help from techsupport if you dont know how to enable it
</NOSCRIPT>

Although I think not relevant, I used Spring MVC 2.5 and Jquery for the sake of information to all.

Any thoughts how others are able to handle in scenario such as this?

like image 793
Mark Estrada Avatar asked Dec 21 '22 22:12

Mark Estrada


2 Answers

I think it's fine to require JavaScript to run your application. All mainstream web browsers have it today, and have had it for the last 10 years.

Using a <noscript> tag is an acceptable way of showing to the user that they need JavaScript. I don't understand what you meant about disabling the login button though... You used JavaScript to detect if JavaScript was disabled ("I used jquery to check for the presence of this tag")?

What you should do is to have the login button disabled by default, then use JavaScript (jQuery) to enable it. That way it will only be enabled if the user has JavaScript enabled.

like image 190
Blixt Avatar answered Jan 04 '23 22:01

Blixt


What you should do is something like so

<noscript>
    <meta http-equiv="refresh" content="url=/?nojs=true">
</noscript>

This will do a html immediate refresh as soon as the headers are parsed allowing you to do something a little different.

Server Side: (PHP in my case)

if(isset($_GET['nojs']) && !isset($_SESSION['no_script']))
{
    $_SESSION['no_script'] = true; //Or cookie
}

Then as you have the variable locked in session / cookie you can throw out different pages for non JavaScript users.

like image 38
RobertPitt Avatar answered Jan 05 '23 00:01

RobertPitt