15

i have a alot of functionality implemented through javascript if at any stage the javascript is disabled he should be redirected to another page. mentioning him to enable the javascript and then proceed. and this functionality should be cross browser compatable Regard,

Shah
  • 1,604
  • 4
  • 20
  • 33
  • I don't know if that is possible. I think you must have JavaScript enabled to redirect in the client, and you can only know that there is no JS engine available in the client... – Elias Dorneles Dec 02 '11 at 11:10
  • Appropriate use of progressive enhancement would make this approach, and the requirement for another page, unnecessary. – RobG Dec 02 '11 at 11:10
  • As a user, I'm probably on your site to view simple text or images. 95% of cases you do not need javascript to display those. I use noscript, and if your site renders itself nonfunctional unless I allow arbitrary code execution I will simply leave your site. –  Jun 10 '13 at 22:11

5 Answers5

21

Use <noscript> tag to check whether JavaScript is enabled or not.<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.google.com/"> will redirect it to the specified url.Here in this example it will redirect to the google.

Here is an example.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>How To Detect If User Javascript Is Enabled</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    .style1 {
    color: #FF0000;
    font-weight: bold;
    }
    -->
    </style>
    </head>
    <body>
    <p>The Purpose of this script is to show if you have javascript enabled in your browser.</p>
    <p class="style1">
    <script type="text/javascript">
    document.write('Javascript is enabled');
    </script>
    <noscript>
    Javascript is disabled.
    <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.google.com/"> 
     </noscript>
    </p>
  </p>
    </body>
    </html>
Rohan Patil
  • 2,328
  • 1
  • 16
  • 23
  • Yes you can redirect. I have tested it and it works.If your javascript is disabled it redirects to google.com. you can specify url to redirect. – Rohan Patil Dec 02 '11 at 11:25
9

Do a http redirect from a noscript block. Like:

<noscript>
    <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html"> 
</noscript>
Bas Slagter
  • 9,831
  • 7
  • 47
  • 78
2

Use the noscript element with a meta redirect.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

You could try this, this will write the message that the javascript is not enabled and refreshes in 5 seconds

<noscript>
Javascript is not enabled in your browser, you'll be redirected to another page.
    <meta HTTP-EQUIV="REFRESH" content="5; url=http://www.mysite.com/nojavascript.html"> 
</noscript>
SaQiB
  • 639
  • 8
  • 18
0

I think the noscript Tag will be helpful in this case. This will execute when javascript is disable. So in this you can have a meta redirect useful

sushil bharwani
  • 29,685
  • 30
  • 94
  • 128