Re: [SMARTY] Setting a variable if javascript is enabled?

From: Date: Wed, 12 Feb 2003 17:08:51 +0000
Subject: Re: [SMARTY] Setting a variable if javascript is enabled?
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7691@lists.php.net to get a copy of this message
I have not needed to use this personally (I mostly develop intranet apps, and I can tell the users to turn on JS if they want my page to work :) so this is untested code: It would look something like this in the tpl: ... <script type="text/javascript"> document.write('<img src="js_test.php" width="1" height="1" border="0">') </script> ... and js_test.php would be: <?php session_start(); $_SESSION['JS_ENABLED'] = true; $img = imagecreate(1,1); $white = imagecolorallocate($img, 255, 255, 255); header('Content-type: image/png'); imagepng($img); ?> in your main php, it would look something like: <?php ... session_start(); $js_enabled = (array_key_exists('JS_ENABLED', $_SESSION) && $_SESSION ['JS_ENABLED'] ) ? true : false; ... This obviously would not work the first time through your application (i.e. you main pages has to tell the browser to fetch the image, then the "image" has to store the fact that it was called in the session. HTH Jason > Hi Jason, > > > You could try something sneaky like having js do a document.write of a 1 > > pixel x 1 pixel image that is a php script. This script could set a > > variable in the session indicating that js is enabled (and then output the > > small image), and the rest of you app could work from that. > Hmm. Sounds complicated. > Could you give me an code-example? > > with regards, > Matthias

« previous php.smarty.general (#7691) next »