-1

I am working on a mobile mail app where I have created 2 versions of the app, the one is for javascript disabled devices. I want to redirect my users (if they visit the app using a javascript disabled device) to the non-js version of my site.

How can I know if the device is javascript disabled from server side?

I tested the following code on a javascript disabled device, instead of printing "Javascript is not enabled", It is returning empty .

$x="<script> document.write('hello world');</script>";

if(empty($x)) {
   echo "Javascript not enabled";
}

Is there something wrong with the code?

Darren
  • 13,050
  • 4
  • 41
  • 79
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • You can't do it via PHP - [read more](http://stackoverflow.com/a/4454557/2518525) (*well you can, with cumbersome, overkill code, but that's not what you want.*) – Darren Jan 04 '16 at 05:28
  • 1
    There is a messy way of doing this. Have your browser check in with the app via an ajax call. If the users session receives no check in within X time then redirect to the non-js app on the next page load - you don't have JS to redirect so you have to wait for the user to take action. This isn't graceful and rather than doing something like this - you should plan for the absence of javascript if that is a major concern. – Ryan Rentfro Jan 04 '16 at 05:30

1 Answers1

1

noscript blocks are executed when JavaScript is disabled.

Example :

<script> 
document.write('hello world');
</script>

<noscript>
    <a href="pagewithoutjs.php?">Some Page</a>
</noscript>

Users without js will get the pagewithoutjs.php

user3227262
  • 563
  • 1
  • 6
  • 16