Is there any way instead of a JS hack where I can post from an iframe to another page outside the iframe?

javascript

No, there is no direct way to post data from an iframe to a page outside the iframe due to security restrictions in modern web browsers.

The Same-Origin Policy is a security measure implemented by web browsers that restricts web pages from making requests to a different domain. This is done to prevent malicious scripts from accessing data on other websites. As a result, if an iframe is embedded in a page from one domain, it cannot directly post data to a page on another domain.

However, there are a few workarounds that you can use to achieve a similar result:

  1. Use the postMessage API: The postMessage API allows you to send messages between frames or windows, even if they are from different domains. You can use this API to send data from the iframe to the parent window, which can then post the data to the desired page. This approach requires cooperation between the parent window and the iframe, and both need to implement the postMessage API.

  2. Use a server-side proxy: You can set up a server-side script on the same domain as the parent page, which can receive data from the iframe and then post it to the desired page on a different domain. This approach requires you to set up and maintain a server-side script, but it provides a more secure way to post data between domains.

In summary, while there is no direct way to post data from an iframe to a page outside the iframe, you can use workarounds like the postMessage API or a server-side proxy to achieve a similar result.