How to get iframe response headers?

2019-02-23 07:45发布

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!

1条回答
何必那么认真
2楼-- · 2019-02-23 07:56

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') );
} } );

This will only work if the iframe src is in the same domain as the calling script.

查看更多
登录 后发表回答