williamZanelli Posted December 19, 2008 Share Posted December 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
tomfmason Posted December 19, 2008 Share Posted December 19, 2008 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. Quote Link to comment Share on other sites More sharing options...
williamZanelli Posted December 21, 2008 Author Share Posted December 21, 2008 Thanks for the reply Tom, I was wondering if you had any example code.. I'm not much of a programmers. Cheers. William Quote Link to comment Share on other sites More sharing options...
Sesquipedalian Posted December 22, 2008 Share Posted December 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
williamZanelli Posted December 23, 2008 Author Share Posted December 23, 2008 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... Quote Link to comment Share on other sites More sharing options...
Adam Posted December 23, 2008 Share Posted December 23, 2008 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 Quote Link to comment Share on other sites More sharing options...
tomfmason Posted December 23, 2008 Share Posted December 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
Adam Posted December 23, 2008 Share Posted December 23, 2008 I think he's asking how though as JS runs after the page has loaded, which means that to test PHP-side for a cookie set via JS, you could only do it on the second request? ..and I didn't know that, cheers! A Quote Link to comment Share on other sites More sharing options...
tomfmason Posted December 23, 2008 Share Posted December 23, 2008 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.