Jump to content

Recommended Posts

Hi guys,

 

I've coded a website, which has alot of JS, as in when someone hovers over the image it expands in size, a caption etc appears.

 

I've realised that 3% of people from my analytics data) who come to my website, dont have JS enabled, what I want is to redirect these guys to a non-JS website,

 

Any ideas on how I go about this? Can someone please post some examples..?

 

Regards

 

Will

Link to comment
https://forums.phpfreaks.com/topic/137750-solved-js-not-enabled/
Share on other sites

The best method that I know of is to set a cookie via javascript and then check it in php. If the variable isn't present and they aren't a search engine crawler  redirect. That and noscript tags to notify them that javascript is required. 

Just set the cookie with javascript with setcookie(); and then check if it exists like this:

 

<?
if (isset($_COOKIE['javascript'])) {
    //JS is enabled
} else {
   //JS is not enabled.. redirect.
}
?>

 

I'm gonna assume you know how to set a cookie with JS since you *did* code the website using JS. Otherwise you can just look it up or something.

Thanks for the reply guys,

 

But i;m still not 100% with your logic,

 

So say a new user (never accessed my website in his life) types in my URL, if the JS is enabled it sets the cookie, I then check in PHP if its enabled, if it is.. ok, otherwise redirect.

 

My point of question lies in that, does the JS get called before the PHP? I was always under the impression the PHP is called first, which would mean, when the check is carried out for a new user, the Cookie is never enabled?

 

Am I right?

 

Thanks in advance for your thoughts...

My point of question lies in that, does the JS get called before the PHP? I was always under the impression the PHP is called first, which would mean, when the check is carried out for a new user, the Cookie is never enabled?

 

On the first request set a session variable. Then check for the cookie.

 

You're correct. I'd say in your situation best thing you could would be something like:

 

<noscript><meta http-equiv="refresh" content="0; url=non_js_page.php"><a href="non_js_page.php">Non-JS page...</a></noscript>

 

A

 

That wouldn't be valid html. The meta tag is not allowed within the body and the noscript tag is not allowed within the head.

 

 

Personally I would just use a noscript tag with a link to the non js version.  If they have javascript disabled (not a search engine or some other type of bot) they most likely already understand that a lot of functionality from a lot of sites is going to be missing. What if they disable CSS? Do we have to support that as well?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.