6

I'm working on a website, and I've run into trouble modifying an HTTP Response header using (client-side) JavaScript. I have exactly zero idea how to do this. I know (roughly) how to make the 'for' loop to modify the header, but I don't know how to access the header within the script. Could y'all fine people help me with this fun task?

11
  • 3
    mind if I ask what you're trying to accomplish by doing this? Commented Jan 15, 2014 at 22:07
  • 1
    But I think this has your answer: stackoverflow.com/questions/220231/… Commented Jan 15, 2014 at 22:08
  • 2
    @Barmar: Depends on where the JavaScript is running. If it's running on the server... Commented Jan 15, 2014 at 22:08
  • 1
    @T.J.Crowder Unless they specifically say they're using something like Node.js, I'm going to regularly assume that JS == client, not server. Commented Jan 15, 2014 at 22:09
  • 1
    Alright, for clarification: I need to modify the response header to remove X-Frame-Options to load one site in an iFrame. Is it possible to have the script run after receipt of the header, then pass the header along to the iFrame afterwards? Commented Jan 15, 2014 at 22:10

1 Answer 1

8

With client-side JavaScript (JavaScript running in a browser), you can't do this; by the time the JavaScript code runs, the headers have already been processed.

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

4 Comments

Hey T.J., I'll defer to your experience, but generally I'd comment on an answer like this that it is better suited as a comment, as it really just asks for clarification...
@ZachL: I was 99% sure the OP meant client-side. That 1% is why I went with CW. :-) (Well, that and there were at least three comments saying "You can't do this with client-side JavaScript..." :-) ) Making it an answer means that if I was right about the OP meaning client-side, it's something they can accept. (You can't "accept" a comment.)
ahhh.. didn't notice the CW tag. Thanks for clarifying. Hope you don't mind I went ahead and removed the "server-side" part from your answer after editting "client-side" into the question.
If I were to implement the proper code server-side, then what code would I need / where the hell would I put this in terms of site directory?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.