PDA

View Full Version : SEO friendly way of detecting if JS is off


Jazajay
12-27-2007, 07:35 AM
Hi all.
I'm in the process of updating my tracking/product page and I was wondering if any one could notice or give me a better solution than what I have / want to do.

What I need is a more SEO friendly way of detecting if JS is turned off.

What I have at the mo is I set a JS variable to the link then test if the JS variable is on on the receiving page, if it is not JS isn't on.

However this has an obvious drawback, as I have recently noticed, namely the first page viewed wont have the JS URL parameter and always returns as a user has JS off.
I could test the refferer but I will either not enter any thing for that page into the DB or have to assume it is on, when it possibly couldn't be, and making my tracking less than perfect.

I have come up with 4 more solutions but these all have major drawbacks.
1. Create an image in JS with it's source pointing to a php page then set a session on that page. if JS is off the session is set to null then test the session.

2. Set a cookie in JS - test to see if the cookie is set

However for these to work the page must be refreshed, otherwise I have my orginal problem, as in via js redirect - not a way I really wont to go as it will refresh once for users but every page will refresh for the bots.

3. Test the second page and set the 1st page in a session then insert into the DB the JS value. However if I have a major problem with my non-js version and people leave my site because of it before clicking on I will not know of any problems and therefore wouldn't be able to fix them.

4. use get_browser however I for a long reason I cant as of yet use it.

The only practical solution seems to cloak the redirect and cookie any one have any better solutions before I have to implement this?
Hope you all had a good xmas
Thanks for reading
Jaza

jimbeetle
12-27-2007, 12:10 PM
Not sure if this will help, but I've seen several variations that use a hidden form field. Basically run a script that sets the value of the form, then test for that value.

Jazajay
12-27-2007, 12:28 PM
Thanks for your contirbution but that would require a page refresh or another page load to work bringing me back to my problem. Dam spammers thats another reason why I hate them

Jazajay
01-21-2008, 04:57 PM
I've come up with the best solution I can.
Ok create an image in JS point the src at an external page.
So something like


<script type="javascript">
var img = document.createElement("img");
img.setAttribute("src","somePage.php?js=on");
</script>


Right, now on the page create a blank object tag pointing to the same page.
<object type="text/plain" data="theSameSiteToTheJsPage.php?name=thisPage"></object>

Ok now on that page create logic similar to below

<?php
if(isset($_GET['name']) && isset($_GET['js']))
{
//if the 2 variables are set js is on
session = js is on
insert into db what ever
}
else
{
//else the JS variable is not present so js = off
js = off
insert into db
}


Walla no cloaking needed and pretty simple.
Maybe tomorrow I will publish some more useful JS tips curtsy of Jazajay
we shawl see :D

jimbeetle
01-21-2008, 05:15 PM
He, he, he. You're a real rip, jaz. Good having you around.

Jazajay
01-21-2008, 05:49 PM
Of coarse it is mate.
As I'm just amazing and slightly god like if I don't say so my self. :D