By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

HTTP header insertion using javascript

P: 3
I would like to use javascript (or something similar) in my page in order to make the browser send a specific HTTP header (let's say the header 'X-Try:' with some value). I would like to do it on every subsequent request to the same domain (The domain that originally sent the javascript to the client).
Can I do such a thing? and if yes - how exactly ?
Jul 19 '08 #1
Share this Question
Share on Google+
6 Replies


rnd me
Expert 100+
P: 427
are you talking about a request header, or a response header ?

you can set request headers in ajax.

you can mimic response headers with meta tags, splicing them into the response and then doc.writing the output, but that's about as good as you can do with just javascript.
Jul 20 '08 #2

P: 3
are you talking about a request header, or a response header ?

you can set request headers in ajax.

you can mimic response headers with meta tags, splicing them into the response and then doc.writing the output, but that's about as good as you can do with just javascript.
I'm talking about injecting request HTTP headers in all subsequent requests that are destined to the same domain as the domain that initially sent that javascript.
I want to embed in my javascript (the one I sent as a response for request#1) a piece of code that will add a specific HTTP header in all the next requests originated from that javascript page.
I prefer using javascript to do that...
but, if there's a way to do that in ajax - can someone elaborate on that ?
Jul 20 '08 #3

dmjpro
100+
P: 2,476
I'm talking about injecting request HTTP headers in all subsequent requests that are destined to the same domain as the domain that initially sent that javascript.
I want to embed in my javascript (the one I sent as a response for request#1) a piece of code that will add a specific HTTP header in all the next requests originated from that javascript page.
I prefer using javascript to do that...
but, if there's a way to do that in ajax - can someone elaborate on that ?
What type of HTTP header you want to add?
And how to add HTTP header before Ajax call, go for Google.
Jul 20 '08 #4

P: 3
What type of HTTP header you want to add?
And how to add HTTP header before Ajax call, go for Google.
I would like to add the HTTP header "X-Try: blabla" inside each subsequent request .
I would like it to be placed somewhere inside the HTTP header of a regular request coming out of the client's browser
Jul 20 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Use the setRequestHeader method of the XMLHttpRequest object.
Jul 20 '08 #6

rnd me
Expert 100+
P: 427
you can use ajax, and a fullscreen iframe to do it.


lets say you had an iframe (id="iframe1") styled to take up 100% of the screen: no body margin or padding:








Expand|Select|Wrap|Line Numbers
  1. function el(tid) {return document.getElementById(tid);}
  2.  
  3. function IO(U, V) {//customized for post...
  4. //LA MOD String Version. A tiny ajax library.  by DanDavis
  5.     var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  6.     X.open(V ? 'PUT' : 'GET', U, !1);
  7.     X.setRequestHeader('Content-Type', 'text/html')
  8.  
  9.     X.setRequestHeader('X-Try', "blabla");
  10.  
  11.     X.send(V ? V : '');
  12. return X.responseText;}
  13.  
  14. var doc = el("iframe1").contentWindow.document
  15. doc.write( IO("page1.htm"));
  16. doc.close()
  17.  
  18.  
Jul 20 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.