How to detect different user settings? Javascript enabled, Cookies enabled
I am wondering how do I first detect if Javascript is enabled/disabled. Disabling javascript on this site revealed that stackoverflow uses something called the tag.
Is this like the standard way of doing it? Does it work on all the browsers?Which browser versions does it not work on(ie IE6)?.
Do I just stick in the body or the head of my html page? I saw one site tutorial that stuck it in the head but Visual Studios said that is not XHtml complaint.
Next how do I check if cookies are enabled? Do you do use javascript to figure this out? Or do you use server side? Is there something that works that works on all major browsers or maybe something in jquery 开发者_开发技巧that does this?
Thanks
Use the <noscript>
tag to display content when JavaScript is disabled - this isn't quite the same thing as 'detecting' if JavaScript is disabled or not. You can't really tell if JavaScript is enabled or not as the only tool available for doing this across most browsers is JavaScript - which obviously you can't use if it's disabled.
To handle clients without JavaScript support (or with support that has been disabled) you need to use progressive enhancement and unobtrusive JavaScript techniques. Make the page do what you want it to do for clients without JavaScript (the starting point) and then add the additional functionality using JavaScript. As the additions won't be applied without JavaScript enabled you effectively get what you want to achieve.
Same principle applies for cookies - get it to do what you want with no cookies then add the behaviour for when they're found.
You can use the <noscript>
tag to detect whether javascript is disabled or not. Well You cannot actually detect instead you can do something like
<noscript>Javascript is disabled. please enable Javascript</noscript>
Also there is no proper way to check whether cookies are disabled. All you can do is save something in the cookie and try to retrieve them.
精彩评论