Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if javascript is available and redirect if javascript is not available [duplicate]

Possible Duplicate:
How to detect if JavaScript is disabled?

In my php application i need to check whether the javascript is turn on or not in browser. I have tried this <noscript><p>javascript is off<p></noscript> it's working fine.But i need to redirect to a page if javascript is OFF so developed like this

<noscript>
<?php header('Location: index.php');?>
</noscript>

But i/ts always redirecting to index.php, there is any way to do this.

like image 281
Rakesh Avatar asked Sep 28 '12 11:09

Rakesh


4 Answers

your solution clearly cannot work, since php is executed before the page is served on client

you could instead do something like

<noscript>
  <meta http-equiv="refresh" content="0;URL='http://example.com/'">
</noscript>

in the head of your document

like image 110
Fabrizio Calderan Avatar answered Nov 16 '22 17:11

Fabrizio Calderan


<noscript><meta http-equiv="refresh" content="1;url=error.html"></noscript>

try this to redirect if JS is disabled Php script runs independently of js

like image 3
Blackrabbit99 Avatar answered Nov 16 '22 16:11

Blackrabbit99


There are known issues with noscript

Instead do this:

<html>

<head>

<script>
window.location.href="javascriptEnabled.html";
/*Since javascript is enabled redirect to javascript based page*/
</script>

</head>

<body>
Showing Static Website since javascript is not enabled..
</body>

</html>
like image 2
Anirudha Avatar answered Nov 16 '22 16:11

Anirudha


There is not a good way to do it, because without client side interactivity, you can not get information back from the client.

You could do something like this...

  1. Set up a meta redirect to trigger after 5 seconds
  2. use javascript to override the meta redirect

Therefore, if javasccript is enabled, you get to the javascript page, otherwise the non javascript page

like image 1
user1706146 Avatar answered Nov 16 '22 16:11

user1706146