Re: HOWTO Q: detect browser's script enabled? - II

From: Date: Tue, 29 Jan 2002 20:25:12 +0000
Subject: Re: HOWTO Q: detect browser's script enabled? - II
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-82605@lists.php.net to get a copy of this message
Ivo Stoykov wrote in news:20020129185128.39173.qmail@pb1.pair.com: > Hello again > > earlier today I asked about detecting whether javascript is > enabled on the visitor's browser (bellow are the question and > answeres received). <html> <head> </head> <body> <script type="text/javascript"> jsImg = new Image() jsImg.src = "js-yes.gif"; </script> <noscript> <img src="js-no.gif" width="0" height="0" alt="" /> </noscript> </body> </html> Your access logs for the images js-yes.gif, and js-no.gif will give you stats over js/no-js. If you need something more sophisticated, you can replace js-yes.gif and js-no.gif with serverside scripts that add the results to a database. I have a sample php-script that gives you some of that functionality without resorting to database: [jsenabled.php] <?php if ($js_=="y"){ $file = "ay.txt"; } else if ($js=="n"){ $file = "an.txt"; } $fp = fopen($file,"a"); fwrite($fp,"1"); fclose($fp); header("Content-type: image/gif"); readfile("spacer.gif"); ?> I then modify the html/js code to look like this: [somedocument.html] <html> <head> </head> <body> <script type="text/javascript"> jsImg = new Image() jsImg.src = "jsenabled.php?js=y"; </script> <noscript> <img src="jsenabled.php?js=n" width="0" height="0" alt="" /> </noscript> </body> </html> Please note that you'd want to purge the an.txt and ay.txt every once in a while. -- Arve <URL:http://www.bersvendsen.com/> Newsere mot X-No-Archive <URL:http://www.ibiblio.org/Dave/Dr-Fun/df9601/df960124.jpg>

« previous php.general (#82605) next »