Samo
Status: New User - Welcome
Joined: 19 Mar 2006
Posts: 3
Back to top
Posted: Mar 19, 06, 15:37    javascript detection
would someone be able to give the code snippet that detects if javascript is enabled or disabled?
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 583
Back to top
Posted: Mar 19, 06, 15:38    
:: Code ::
<noscript>Javascript is disabled</noscript>


Or of course any other content you want to put in the noscript tag. If that's not your question you'll have to use more words to describe what you want to know.
Samo
Status: New User - Welcome
Joined: 19 Mar 2006
Posts: 3
Back to top
Posted: Mar 19, 06, 15:50    
no, that's what i wanted, but, um, how would i be able to base an if/else statement off that?
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 583
Back to top
Posted: Mar 19, 06, 16:21    
Not a bad question as they go:

:: Code ::
<!-- if javascript is enabled -->
<script type="text/javascript>some_function();</script>
<!-- else if not enabled -->
<noscript>straight html for what you want to show</noscript>


I just included the html comments to show that this is actually an if type statement, only minus the literal 'if... else' words.

There is another way to use php to detect javascript, but it requires reloading the page, which in general is a pretty bad idea for standard pages.

Obviously you can't have any real if/then type syntax in the html itself, that would only work with some scripting language, and in the case of javascript, the thing has to work if javascript is turned off, and this is how you handle that case.
Samo
Status: New User - Welcome
Joined: 19 Mar 2006
Posts: 3
Back to top
Posted: Mar 19, 06, 18:34    
ok, thx, i'll let you know if i need any more help
Display posts from previous:   

All times are GMT - 8 Hours