Forum Moderators: coopster

Message Too Old, No Replies

If statement for javascript

         

pheonix123

11:48 am on Apr 1, 2008 (gmt 0)

10+ Year Member



Hi,

Is it possible to have something like:

if (the user has javascript enabled)
show html content A;
else
show html content B;?

If so how would I go about it?

Cheers

Alternative Future

12:18 pm on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi pheonix123,

I think you would have to use something like:
<noscript> [w3schools.com...]
as I don't think you could use any form of client-side script to do the check due to scripting beiong disabled.

HTH,

-Gs

pheonix123

12:49 pm on Apr 1, 2008 (gmt 0)

10+ Year Member



Hmm, guess I'll have to try and fiddle about with my javascript to make sure it displays the content in some way if it is disabled.

Thanks

PHP_Chimp

1:40 pm on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You wont have any luck fiddling with javascript to get javascript to work on a page where the user has javscript turned off...as that is exactly the point of turning javascript off.

If you make use of the <noscript>tags then you could either put a message saying "turn your javascript on" (particularly stupid message; as those people that are computer literate enough to turn it off dont want it on, and those that cant use javascript cant turn it on...however you see this message on hundreds of sites if you turn off your javascript and browse) or if you are using some ajax to alter content then use PHP to put the content there and have a refresh button, so that they can click to get the latest content. Or just have static text to give people another method of accessing that content i.e.


<script type="text/javascript">weatherMap()</script>
<noscript>View our <a href="weather_map.php">weather map</a></noscript>

[edited by: PHP_Chimp at 1:41 pm (utc) on April 1, 2008]

penders

1:58 pm on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think similar to what PHP_Chimp says in the later half...

If it's just a case of displaying A or B then... display content B by default. Use JavaScript to display content A. Content A will only display if JavaScript is enabled. (Not really PHP though?)