cotsweb is running a little trial to answer the question What percentage of browsers have javaScript enabled?. This site isn’t busy enough to give a useful answer but we are using it as a trial to make sure that our method works and that it doesn’t mess up the existing site before rolling it out to a busier site.
Method
It’s quite simple in principle. When a user loads one of the pages we are using for this test several things happen:
- A PHP script creates a session on the server and logs this in a mySQL database
- If no session exists already then the PHP script writes a little bit of javascript into the HTML page to be served
- If the client has javaScript enabled on their computer the script will run sending an asynchronous call (to avoid slowing down the pageload while waiting for a response from the server) to the server
- Another PHP script on the server will find the mySQL record created in step one and update the javascript_enabled flag
- If the client doesn’t have javaScript enabled then the script won’t run and the database will not be updated
Results
So far we have checked ‘. $records . ‘ sessions and ‘ . $enabled . ‘ of them have had javaScript enabled, a rate of ‘ . round($percent_enabled,1) . ‘%.
‘);
}
?>
We will give this trial a little time and a bit of analysis before we roll this out for some proper results (and publish the code so other people can do the same).
Edit: Well the first change was to exclude robots, Googlebot and Slurp from Yahoo! were very quick on the scene and of course they don’t use javaScript.
Further Edit: 31st Aug 2010 The second change was to remove the logging from this page, it seems like my little script was interfering with something in the header of the blog page, perhaps Google Analytics.
I am suspicious about the very low percentage of javaScript we are seeing, further investigation is required. It could be that people are reading this post through feed readers rather than directly and so not activating the script.
Further Edit: 6th Sep 2010 Something isn’t right here, the logging works for me but the numbers look far too low. I wonder if there is something wrong with my javaScript code (I am no javaScript expert) which is causing it not to make the ajax call for most people. This is the code that is included into the header of the testing page:
<script type="text/javascript">
//
// This script is part of my javascript logging routine.
// If javascript is enabled it sends a request to the server which will log the fact that javascript is enabled.
//
// The cunning bit which copes with the fact that IE6 doesn't know about XMLHttpRequest, thanks to
// http://ajax-prototype.blogspot.com/2007/02/workaround-to-make-ajax-calls-on.html
//
if (!window.XMLHttpRequest) {
window.XMLHttpRequest = function() {
return new ActiveXObject('Microsoft.XMLHTTP');
}
}
//
// Send the PHP session_id to the server script so it can update the log record for this session
//
request=new XMLHttpRequest();
request.open("GET","http://www.cotsweb.com/update_javascript_log.php?session_id=<?php echo(session_id()); ?gt; ,true);
request.send(null);
</script>
Perhaps someone else can see what I have done wrong?