Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Load different PHP files based on JavaScript availability

I currently have the code below (PHP)

<?php
    require_once __DIR__.'/includes/Connect.php';
    require_once __DIR__.'/includes/Nojs.php';
    require_once __DIR__.'/includes/Main.php';
    require_once __DIR__.'/includes/footer.php';
?>

I want Main.php to load only if JavaScript is enabled, and Nojs.php to load only is JavaScript is disabled.

Surrounding Nojs.php with tags does nothing (See below code)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?php
    require_once __DIR__.'/includes/Connect.php';
?>
<noscript>
    <?php
        require_once __DIR__.'/includes/Nojs.php';
    ?>
</noscript>
<?php
    require_once __DIR__.'/includes/Main.php';
    require_once __DIR__.'/includes/footer.php';
?>

Since I know the PHP cannot access the browser as it is done server-side, is it possible to try to use HTML (Like I attempted) or other JavaScript to get it to work?
Thanks in advance.

>Solution :

Create another PHP file with no js version when first PHP loaded it will check if no js support will redirect to no js version of PHP


<noscript>
  <meta http-equiv="refresh" content="0;url=nojs-version.php">
</noscript>    

Edit: It is also mentioned by W3C as technique without confusing user
https://www.w3.org/TR/WCAG20-TECHS/H76.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading