9

Is there a way to get the header of the current page in angularjs, without having to do a separate call? I can't find this in the docs anywhere, but it seems like it should be possible.

E.g. if the file index.html contains the angular code, how do I read the header of the initial request to get index.html? I could use $http to make the call again, but that seems unnecessary.

9
  • You can't access page headers via Javascript, without an ajax request, so you may be able to get the initial route, but not the index. Commented Oct 24, 2014 at 22:44
  • Can't really understand your question. Can you elaborate? Commented Oct 24, 2014 at 22:44
  • 1
    @NoahMatisoff my angular code is referenced by an html file, which causes the script to be loaded. How do I get the header for that html file? For example in chrome debugger I can just click Network tab then select the HTML file and view the header. Is there a way to read this with angular? Commented Oct 24, 2014 at 22:46
  • The question for index http headers duplicates - stackoverflow.com/questions/220231/…. Commented Oct 24, 2014 at 22:49
  • 1
    @tyler same thing, if you are not handling the http request you won't have access to the request or the response, unless the code that it's making the request exposes that information somehow, which is not the case. So, I'm sorry but the answer is no. However, if I may: what is exactly what you need from the response header? Because there could be other ways to obtain the information of the headers (i.e. cookies) Commented Oct 24, 2014 at 22:59

1 Answer 1

4

If you are not handling the http request you won't have access to the request or the response, unless the code that it's making the request exposes that information somehow, which is not the case. So, I'm sorry but the answer is no.

However, if I may: what is exactly what you need from the response header? Because there could be other ways to obtain the information of the headers (i.e. cookies)

Sign up to request clarification or add additional context in comments.

1 Comment

The use is for tracking environment variables. We can embed directly onto the page and then just read it, but was trying to go through headers if possible. Cookies are not an option.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.