开发者

XMLHttpRequest referrer and iframe

开发者 https://www.devze.com 2023-03-03 16:15 出处:网络
Page A contains javascripts function executing XMLHttpRequest. Page A loads page B in iframe. Page B executes parent.makeRequest() function which in turn executes the XHR request. I expect the refe开发

Page A contains javascripts function executing XMLHttpRequest. Page A loads page B in iframe. Page B executes parent.makeRequest() function which in turn executes the XHR request. I expect the refe开发者_Python百科rrer/origin of the XHR request to be page B, however it is page A. Is there any way to fix this?


You cannot control the value of the Referer header.

Some HTTP headers can be adjusted when making XHR requests using the setRequestHeader method. However, the Referer header is specifically excepted. From the specifications:

The above headers [including Referer] are controlled by the user agent to let it control those aspects of transport. This guarantees data integrity to some extent.

You could, however, set a custom header. For instance, you could use X-Referer, if this suits your application:

xhr.setRequestHeader('X-Referer', location.href);
0

精彩评论

暂无评论...
验证码 换一张
取 消