Search code examples
javascriptpostmessage

How to use "postMessage API" to Get iframe Response headers


I have an iframe that loads a URL (the URL not in my domain) and that URL after it loads inside the iframe gives 302 redirect. My question is that is it possible to get that 302 redirect URL value after the iframe loads using JavaScript or postMessage API or anything else?
Note : the loaded Url is not mine (not in the same domain)


Solution

  • Short answer is no.

    The author of the page must insert the code necessary to use the Messaging API to "send" a message to the parent window.

    So without the above, cross document and cross origin you cannot use the Messaging API.

    Also, without CORS, you will not gain access to the iframe contents to scrape that data either.