I'd like use Javascript to find out my browser's default HTTP Accept-Language that it sends in an HTTP request. I'm aware that Javascript's XMLHTTPRequest Object has a getResponseHeader()
method. Does it have a similar method for getting request headers? Or is there another way I can determine my browser's HTTP request header?
Asked
Active
Viewed 2,579 times
2

sideshowbarker
- 81,827
- 26
- 193
- 197

Brinley
- 591
- 2
- 14
- 26
-
Possible duplicate of: https://stackoverflow.com/questions/220149/how-do-i-access-the-http-request-header-fields-via-javascript – Allen G Jun 08 '18 at 18:29
-
It's not a duplicate. https://stackoverflow.com/questions/220149/how-do-i-access-the-http-request-header-fields-via-javascript wanted to know User-Agent and Referrer. I'm want Accept-Language – Brinley Jun 08 '18 at 18:37
-
https://stackoverflow.com/questions/1043339/javascript-for-detecting-browser-language-preference ? – user2226755 Jun 08 '18 at 19:11
-
As far as the general question of getting access to request headers from your frontend JavaScript code, see the part of the answer at https://stackoverflow.com/a/220175/441757 which says, *“Almost by definition, the client-side JavaScript is not at the receiving end of a http request, so it has no headers to read.”*. You can’t get access from your frontend code to headers that the browser itself sets after evaluating and executing your frontend code. In other words, your frontend code executes before the request headers are set. – sideshowbarker Jun 08 '18 at 23:45
-
Possible duplicate of [Best way to determine user's locale within browser](https://stackoverflow.com/questions/673905/best-way-to-determine-users-locale-within-browser) – Heretic Monkey Jun 08 '18 at 23:53
1 Answers
4
The main language :
navigator.language
All languages :
navigator.languages

user2226755
- 12,494
- 5
- 50
- 73