最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

httprequest - Why don't browsers send whether they have javascript enableddisabled in the request header? - Stack Overfl

programmeradmin2浏览0评论

It just seems like something that would be really useful when developing server-side code. If you know that the browser won't be using javascript from the server-side, you could easily acmodate the user. Or if you just felt like it, redirect them to a page that says 'hey... we need you to use javascript for our application' etc.

Does anyone know why this is?

It just seems like something that would be really useful when developing server-side code. If you know that the browser won't be using javascript from the server-side, you could easily acmodate the user. Or if you just felt like it, redirect them to a page that says 'hey... we need you to use javascript for our application' etc.

Does anyone know why this is?

Share Improve this question asked Feb 16, 2011 at 22:10 aaronaaarona 37.4k45 gold badges145 silver badges194 bronze badges 2
  • The question is "why", so it has nothing to do with programming, but if you had asked "how", I would have answered: You can write a javascript which will tell the server that javascript is enabled. If it doesn't, then it is disabled. – zvone Commented Feb 17, 2011 at 0:01
  • @zvone - that would result in 2 requests, and if one dares doing that on SO you get down-voted, and if you propose some solution you get down-voted too because it's not "perfect" .. SO used to be great, now it seems opinions win over fact ... geeks and their BS. – user4244405 Commented Feb 15, 2018 at 3:28
Add a ment  | 

5 Answers 5

Reset to default 2

See the <noscript> tag, here.

I know it's probably not ideal (I don't have enough experience with it to pick it apart) but it certainly gives us enough flexibility to degrade somewhat gracefully.

As handy as it would be to have your server be aware of your browser's Javascript capability before page rendering began, I can see a strange edge case such as:

// hide malicious code from people without javascript
if ($header['javascript'] == 'false') {
    show_regular_safe_website();
} else {
    use_some_nasty_javascript_exploit();
}

One way I use is to have a landing page/login page. When the user presses the logon button then use javascript to submit the results or update a hidden field before posting the logon. If javascript is disabled then the javascript will not work and therefore you can assume they have it turned off.

The real reason is that when Netscape came out with JavaScript, they never thought to make the information available in the HTTP headers. Instead they created the <noscript> tag.

I suppose the Accept field could be used to such a purpose, like "Accept: text/javascript". But since it's proprietary the IETF would never include it in any standards and widespread adaptation is therefore unlikely. Web-developers has coped so far.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论