Detecting Javascript (was Re: Newsgroup status)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 On Wednesday, April 27, 2011, Ashley Sheridan wrote:

> Firstly, please do not hijack a thread, if you have a question, start
> your own. We won't bite if you create new threads, whereas we might a
> little if you hijack ;)

Ouch! My apologies - Hijacking was not intended and I've changed the
subject to reflect that this is a distinct 'branch'.

> There are ways to detect the general capabilities of the client machine,
> however they are generalisations, and may not be accurate. Try and grab
> an up-to-date browscap.ini file, and use this in conjunction with the
> user agent string found in the $_SERVER array. This should tell you
> whether the user agent is capable of running Javascript.

Thanks for your reply. As you wrote, identifying the 'alleged' user
agent in that way is not accurate. For example, I run Opera with JS
disabled to check what my work looks like without JS and I know some
who run without JS for security reasons.

My immediate concern is a large form where two data entry fields are
implemented as image maps. The easiest way of presenting this to the
user is as a DHTML tabbed page with AJAX to store x/y locations of the
image map clicks in hidden fields.

However, the page still has to work without JS. So my thought was that
if I could detect whether JS is available at the client, I could serve
different content dependent on JS status. AFAICT, there's nothing that
lets me know 'at first hit' although for pages that aren't directly
accessed (e.g. stuff for which you need to log in each session), it's
possible to use Javascript to write a hidden field. When the user logs
in, this is used to detect that JS is available and to set a session
cookie that you can use on subsequent pages to determine that JS is
there.

That said, I've done some sideways thinking. If JS is not available
then client-side scripts don't run. Clicking image maps or submit
buttons produce the default behaviour and onClick, onChange etc.
events aren't triggered. So I've laid out the page for no JS and then
used an onLoad function to hide the appropriate content. I've also
coded the form handling PHP script to refresh the form with the
appropriate values if one of the image maps is clicked. That way, the
onClick etc. events can be used to trigger AJAX if JS is available and
make an 'interim form submission' if it's not.

However, it would be so much simpler if I could tell straight off and
for sure whether JS was available; but if this isn't possible I guess
it'll be a limitation of HTTP rather than PHP.

Thanks again,

Geoff


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux