title: Listen for iframe event - on open a url
body: <p>I have an iframe embeded in my mobile site, which the content of the iframe contains an image with  tag. I want to listen for the event which user click on the image in the iframe, and redirect to a new page.</p>
  
  <p>For example:</p>
  
  <pre><code>&lt;!-- This is the content of the iframe --&gt;
  &lt;!-- The hosting location is http://www.example.com/iframe.html --&gt;
  &lt;a href="http://www.google.com" target="_blank"&gt;
  &lt;img src="http://www.example.com/image01.jpg"&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>And then</p>
  
  <pre><code>&lt;!-- This is the content of the mobile site --&gt;
  &lt;html&gt;
  &lt;meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/&gt;
  &lt;iframe src="http://www.example.com/iframe.html"&gt;&lt;/iframe&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So when user click on the image in the iframe, he will be redirected to <a href="http://www.example.com" rel="nofollow">http://www.example.com</a>, and I want to listen for this event, which I can dynamically run some javascript functions.</p>
  
  <p>Any suggestions? Thanks.</p>
  
  <p><strong><em>Remarks on 9Dec2014:</em></strong></p>
  
  <p>One thing have to take care is, the content of the mobile site is delivered dynamically into multiple mobile sites with different domains. So window.parent doesn't work because the iframe content file and the html file is not in the same domain.</p>
  
  <p>I also checked the method postMessage(data, targetDomain). However, it can only works under the condition that the domain of the iframe content file and the html file is known. (in my case, the domain of the html file is not known as it is dynamically delivered on multiple mobile sites with different domains).</p>
  
  <p>Any solutions??</p>