How to redirect if JavaScript is not enabled in a browser?


To redirect if JavaScript is not enabled in the web browser, add a script to the <noscript> tag. Let us say you need to redirect to index.php if JavaScript is not enabled. 

Example

Here’s how you can do this:

<!DOCTYPE html>
<html>
   <head>
      <title>HTML noscript Tag</title>
   </head>
   
   <body>
      <script>
         <!--
            document.write("Hello JavaScript!")
         -->
      </script>
     
      <noscript>
         <style>html{display:none;}</style>
         <meta http-equiv="refresh" content="0.0;url=nojs/index.php”>
   </body>
</html>

Above, we first use CSS style, since we do not want the actual page to be visible if JavaScript is disabled in the web browser.

Updated on: 03-Jan-2020

646 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements