are there any web browsers that do not sup开发者_运维知识库port javascript? and how to identify if client is using one of those browsers? or client has disabled javascript?
are there any web browsers that do not support javascript?
Of course. Lynx is just one example.
and how to identify if client is using one of those browsers?
Using the <noscript>
tag to provide alternate content.
or client has disabled javascript?
Same answer as previous : using the <noscript>
tag.
You should never test if a client is using X or Y browser. Always perform feature detection. Step one: use <noscript>
for providing alternate content to clients that do not support javascript. Then test whether the client supports the feature you would like to use. Never test if IE8 or FF3 or something else, ...
Modernizr is an excellent framework which could aid you with this. So if you want to use some of the new cool HTML5 features, don't test if the browser is such and such version: test if the browser supports the feature you would like to use.
As if you will working with CSS :
Many adding no-js
class in <html>
tag like..
<html class="no-js">
and they do replace no-js
to js
by javascript later, like..
<script>
document.documentElement.className = document.documentElement.className.replace('no-js','js');
</script>
So when client has disabled javascript.
Example use :
HTML :
<div class="test">This box with some JS function</div>
CSS :
.no-js .test {display:none;}
Hide this box, when client has disabled javascript.
or..
HTML :
<div class="alert">Please, turn you JS on!</div>
CSS :
.js .alert {display:none;}
Hide alert box when JS is on. But still show when JS if off..
Or do something many more... with no-js
or js
classes..
If your looking for HTML tag for detection :
just <noscript></noscript>
as another say
All of the modern major browsers support JavaScript. There are however some that do not, but with an incredibly small user base relative to the main ones. Some users may disable JavaScript, in which case you can specify different content for those users using noscript
tags.
Do you use any javascript framework ? (jquery, prototype...) They can abstract a big part of browser specificities.
To detect user browser, you can use the navigator object : http://www.javascriptkit.com/javatutors/navigator.shtml
And, as James and Darin pointed out, you can use the <noscript>
tag for alternate content.
精彩评论