How to handle when javascript is turned off

11,483

Solution 1

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.

Solution 2

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.

Share:
11,483
Mark Estrada
Author by

Mark Estrada

Updated on June 19, 2022

Comments

  • Mark Estrada
    Mark Estrada almost 2 years

    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?

  • lock
    lock over 13 years
    here's the code to do the same for JSP (Spring to be exact) mkyong.com/wicket/…
  • Mark Estrada
    Mark Estrada over 13 years
    . Sorry I mixed up what I have been thinking... No Jquery interaction in this case since javascript is turned off
  • Mark Estrada
    Mark Estrada over 13 years
    . I think I will go with what you have suggested. Disable the Login Button then enable it if javascript is turned ON. Thank you...