如何获得iframe响应标题? [英] How to get iframe response headers?
问题描述
有没有办法获得iframe onload的响应头?
Is there a way to get response headers of an iframe onload?
我已经使用了它,但实际上我找不到有用的东西!
I have already googled it, but really I could not find something useful about it!
推荐答案
不是。如果iframe位于同一个域中,则可以访问其包含一些有用信息(如 document.referrer
)的文档对象,但是如果不制作Ajax,则无法拦截完整的HTTP标头请求URL。这意味着再次请求URL。例如:
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. This would mean requesting the URL again. e.g:
$.ajax( { url: $(#myFrame).attr('src'), success: function(r,x){
console.log( x.getResponseHeader('SomeHeader') );
} } );
只有当iframe src与调用脚本位于同一个域时才有效。
This will only work if the iframe src is in the same domain as the calling script.
这篇关于如何获得iframe响应标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!