2

I have an iframe in my JQuery code like this:

var iframe = $('<iframe height="500px">');
        iframe.attr('src', 'someUrl');

which I execute within a function after a condition is met, and it is working as expected. In the url I am also generating and adding some headers to the response which I can see in the network tab of chrome. I would like to access those headers if possible (AJAX call is not an option as this url produces pdf which I am displaying in an iframe within a div). By following this post I tried:

var iframe = $('<iframe height="500px">');
        iframe.attr('src', 'someUrl');
console.log(iframe.contents().find("someHeader").html());

which results in undefined. How can I access those response headers which I can see in the browser's inspection?

Alberto Moro
  • 1,014
  • 11
  • 22
sticky_elbows
  • 1,344
  • 1
  • 16
  • 30
  • https://stackoverflow.com/questions/17250103/how-to-get-iframe-response-headers may help. – Hikmat Sijapati Nov 30 '18 at 14:28
  • Ajax would be only way. – charlietfl Nov 30 '18 at 14:41
  • @charlietfl Thanks, unfortunately with ajax i cannot display the pdf in a div, or can i? – sticky_elbows Nov 30 '18 at 14:46
  • But you can make a different ajax HEAD request to get the headers. Not sure why you are doing this , seems strange to me – charlietfl Nov 30 '18 at 14:49
  • @charlietfl I have to use iframe because the controller I am calling with the iframe is producing pdf which I am only allowed to display in a div. The controller is also doing some checks with the produced pdf file and adding headers to inform the browser whether the checks failed or passed. Now if I make an ajax call, I can't display the pdf in a div, and if I do it with iframe i can display the pdf in a div but can't access the information about the ckecks. what should i do? – sticky_elbows Nov 30 '18 at 15:40
  • Well you can't intercept iframe request so think of a different approach. Perhaps store something in session and use ajax to get that – charlietfl Nov 30 '18 at 15:49
  • thats a very good idea actually, I will try and store the information in a session object. Thanks.. – sticky_elbows Nov 30 '18 at 15:52

0 Answers0