Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No-Javascript Detection Script + Redirect

I would like to write a script that detects whether the user has javascript disabled, and if yes, redirect them to another page (let's say mysite.com/enablejavascript)

However, I have no idea where to start! Thanks SO.

like image 906
Hugo Avatar asked Mar 27 '12 18:03

Hugo


People also ask

How do I know if JavaScript is enabled Linux?

To disable it, or check it is enabled, type about:config in the URL field and confirm that you are not scared of dragons. Search for JavaScript:enabled . If it says true in the right hand column, JS is enabled. To change the setting, click on it and then click Toggle.


2 Answers

Gdoron mentioned noscript already. Together with meta refresh¹ you can redirect users if they have JavaScript disabled.

A JavaScript redirect can be done with location.replace(URL).

<head>
  <noscript>
    <meta http-equiv="refresh" content="0; url=http://example.com/without-js" />
  </noscript>

  <script>
    location.replace('http://example.com/with-js');
  </script>
</head>

Example of noscript+meta refresh: http://pastehtml.com/view/bsrxxl7cw.html

1) Mind the drawbacks section of the Wikipedia article!

Meta refresh tags have some drawbacks:

  • If a page redirects too quickly (less than 2-3 seconds), using the "Back" button on the next page may cause some browsers to move back to the redirecting page, whereupon the redirect will occur again. This is bad for usability, as this may cause a reader to be "stuck" on the last website.
  • A reader may or may not want to be redirected to a different page, which can lead to user dissatisfaction or raise concerns about security.
like image 116
kay Avatar answered Sep 18 '22 17:09

kay


How do you want to write a script when java-script is disabled... ?

It's can not be done. You can show a message when javascript is disabled with <noscript>.

<noscript> tag on MDN:

The HTML NoScript Element () defines a section of html to be inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser.

like image 27
gdoron is supporting Monica Avatar answered Sep 17 '22 17:09

gdoron is supporting Monica