MyBB Community Forums

Full Version: Do you think my plan would work?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My site is going to have a lot of JS/AJAX features and there is no real way to detect if JS is enabled so i thought of this plan:

I set a cookie with php, and using Javascript i unset it. If the cookie was unset, then the user has JS enabled, if not i switch to no JS on the site.

Of course i could do it vice-versa and set the cookie with JS and unset it with php.

I am aware that there are probably plugins for browser out there that remove JS from a webpage, but this will at least take care most of the problems.

Do you think it would work?

P.S
Merry Christmas!
What is the reason you want to do it?
Because i want to have JS/Ajax enabled pages. But if the user has it disabled then most of the site would not work. This way i can at least check if it's enabled/disabled and handle it from there
I think the best solution is make it degradable if Javascript is disabled. Of course it's not going to be the same experience then with JS enabled but people are deliberately choosing to disable Javascript and the ones that do know the consequences of it. And it's also depending on your userbase if you're website is for more tech savvy users the changes that JS is disabled is higher than a website for average users. And to be honest this is only about 90% of the people who disabled Javascript and they all choose for it thyself because no browser comes with JS disabled by default.

Most Javascript libraries (like jQuery, Prototype, ...) and their plugins are fully degradable for browsers with JS disabled. The best practice is to make it work without JS first and then enhance it with JS.

I have an alternative for your question: you can redirect using Javascript and setting a querystring variable, store the information in a PHP session and redirect back to the page. A simplified example:
<?php
session_start();
if(!isset($_SESSION['jsenabled']) && $_SESSION['jsenabled'] != true)
{
     if(isset($_GET['jsenabled']) && $_GET['jsenabled'] == 1)
     {
         $_SESSION['jsenabled'] = true;
         header("Location: index.php");
     }
}
?>
<html>
<!-- ... -->
<script type="text/javascript">
<?php if(!isset($_SESSION['jsenabled']) && $_SESSION['jsenabled'] != true): ?>
window.location.href = "index.php?jsenabled=1";
<?php endif; ?>
</script>
When JS is disabled the session variable is never set and when JS is enabled only the first request is redirected of the session.