Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As <a href="https://stackoverflow.com/questions/2067029/getting-around-same-origin-policy-in-javascript-without-server-side-scripts/2067065#2067065">David Dorward</a> mentioned, JSON-P is the simplest and fastest; however, there is another trick, specifically using two iframes. </p> <p>Two get around this issue without using JSONP, you can do the following. This technique assumes that you have some sort of development access to the parent page.</p> <p>There are three pages on two domains/sites.</p> <ol> <li>Parent page</li> <li>Content page</li> <li>Cross-domain communication page (aka "xdcomm")</li> </ol> <p>Pages the parent and xdcomm pages are hosted on the same domain, the content page is hosted on any other domain. The content page is embedded as an iframe in the parent page and the xdcomm page is embedded as a hidden iframe in the content page.</p> <p><img src="https://i.stack.imgur.com/gle0i.gif" alt="enter image description here"></p> <p>The xdcomm page contains a very simple script that detects GET parameters in the query string, parses that string for <code>method</code> and <code>args</code> variables (where <code>args</code> is a JSON encoded string), and then executes the specified method with the specified arguments in the parent page. An example can be <a href="http://jsbin.com/ilomi5" rel="nofollow noreferrer">seen here</a> (view source).</p> <p>Even though JavaScript's Same Origin Policy restricts code on one domain from accessing that of another, it doesn't matter if domains are nested within each other (domain A, nested within domain B, nested within domain A).</p> <p>So, in a nutshell, the content page sends messages to the parent page via the xdcomm page by changing the source of the iframe to something like <code>http://domaina.com/xdcomm.html?src=foo&amp;args=[1,2,3,4]</code>. This would be equivalent to executing <code>foo(1,2,3,4)</code> in the parent page. </p> <p>Also, know that there are already libraries that help you with this, such as <a href="http://easyxdm.net/" rel="nofollow noreferrer">easyxdm</a>. What I've explained here is the basis of one of the techniques that they use, and while it might not be as fancy, it is certainly a fully functioning and lightweight implementation.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload