If you have developed a page which depends on JavaScript for form validation or for any other purposes then you would be interested in detecting the setting of the client browser and would like to redirect to a different page explaining how to enable or disable JavaScript. Here we will discuss how to check this setting and redirect to a different page accordingly. We can detect this by using noscript tag and if the JavaScript is disabled then the code within this noscript tag will be executed. Here is the code to do that. This code will detect if the script setting is disabled and will redirect to a page explaining how to enable or disable JavaScript. This code will will also redirect the page with meta refresh in 2 seconds.
Demo of javaScript support and redirecting
Here is the code
<html>
<head>
<title>Demo of Checking if JavaScript is enabled in web browser</title>
</head>
<body >
<noscript>
<meta http-equiv="refresh" content="2; URL=enable_javascript.php">
Are you using a browser that doesn't support JavaScript?<br><br>
If your browser does not support JavaScript, you can upgrade to a newer browser<br><br>
If you have disabled JavaScript, you must re-enable JavaScript to use this page. To enable JavaScript:
</noscript>
<br><br>
If you are not seeing any message above this line then you have JavaScript enabled in your browser.
</body>
</html>
In the above code check this line
<meta http-equiv="refresh" content="2; URL=enable_javascript.php">
This line redirects the browser to a different page after 2 seconds. You can change the time duration by changing 2 seconds to any other value.
← Subscribe to our YouTube Channel here