2

I have a page from another domain rendered into my main website and positioned to show the relevant content:

<div id="containerdivonparentsite" style="position:relative;overflow:hidden;width:350px;height:650px;">
 <iframe style="position:absolute;top:-230px;left:-700px;" 
         scrolling="no" width="20000" height="5000" 
         src="http://www.otherdomain.form.com/myform" ></iframe>
</div>

The rendered sub-page contains a form with a submit button. When the user clicks the submit button, a POST HTTP request is issued. Is is possible to somehow "hook" on this POST request in the parent site without enabling CORS?

I would want something like

 $('#containerdivonparentsite').onPOST(function (request) { 
      alert('A POST request was issued by something inside this div. Probably the user clicked a submit button in the iframe.');  
 })

or maybe a global POST event subscription.

$(document).onPOST(function (request){alert('A POST request was issued on the site. It might be coming from an iframe');})
Kornél Regius
  • 2,989
  • 5
  • 30
  • 39

1 Answers1

2

CORS won't help you at all with this.

To communicate across frames on different origins you need to use postMessage and friends.

Like CORS, this does require the two sites to co-operate.

The parent site needs to listen for a message event. The form handler page needs to include a script that will called postMessage and include whatever data is desired in the message.

There is no way for one site to access communications between the browser and another site without the cooperation of either the other site (CORS, JSONP, postMessage, etc) or the browser (extensions).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335