So i want to send a XMLHttpRequest POST request through an iFrame on page load. Reason for posting via an iFrame is to not show referrer.
Javascript:
function load() {
var http = new XMLHttpRequest();
var url = "action url here";
var params = "name1=one&name2=two";
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
http.send(params);
}
HTML:
<body onload="load();">
<iframe name="f1" src="about:blank" id="noreferer" width="0px" height="0px" style="border: 0px none;"> </iframe>
</body>
How can i attach the Request to the iFrame. Any help would be appreciated.
UPDATE:
For anyone asking why i added and fired load();
in the HTML body, Below is a no referrer post request code connected to the f1 iframe via innerHTML
that works in all browsers because the src is 'about blank'
. But not a XMLHttpRequest and doesn't give ability to add headers.
Javascript:
function load() {
var postdata = '<form id=NoReferrerPost method=POST action=\'action url here\'>' +
'<input type=hidden name=name1 value=one />' +
'<input type=hidden name=name2 value=two />' +
'</form>';
top.frames['f1'].document.body.innerHTML=postdata;
top.frames['f1'].document.getElementById('NoReferrerPost').submit();
}
So what is still needed is a way to attach a XMLHttpRequest to post in iframe f1 like my code above.
HERE ARE SOME SOLUTIONS THAT PARTIALLY WORKS:
The solution of @fedeghe HERE using src="data:text/html
with no-referrer meta tag, could work on some browsers.