简体   繁体   English

如何获取iframe响应标头?

[英]How to get iframe response headers?

Is there a way to get response headers of an iframe onload? 有没有办法获取iframe onload的响应标头?

I have already googled it, but really I could not find something useful about it! 我已经用谷歌搜索了,但是实际上我找不到有用的东西!

Not really. 并不是的。 If the iframe is on the same domain you can access its document object which contains some useful information such as document.referrer , but you cannot intercept the full HTTP headers without making an Ajax request for the URL. 如果iframe在同一个域中,则可以访问其包含一些有用信息的document对象,例如document.referrer ,但是如果不对URL进行Ajax请求,则无法截取完整的HTTP标头。 This would mean requesting the URL again. 这意味着再次请求URL。 eg: 例如:

$.ajax( { url: $(#myFrame).attr('src'), success: function(r,x){
    console.log( x.getResponseHeader('SomeHeader') );
} } );

This will only work if the iframe src is in the same domain as the calling script. 仅当iframe src与调用脚本位于同一域中时,此方法才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM