title: How can I access an iframes document event mouse position from the parent window using Javascript and or jQuery
body: <p>I have an iframe inside of a parent window, with both the iframe src and the parent located in the same domain. In order to keep the iframe document clear of Javascript I want to be able to use a function in the parent window to get the the mouse position inside the iframe.</p>
  <p>My attempts at this so far have included:</p>
  <pre><code>&lt;iframe id=&quot;iframe1&quot; src=&quot;test.html&quot; style=&quot;position:relative; width:500px; height:500px&quot;&gt;&lt;/iframe&gt;
  &lt;div id=&quot;result&quot; style=&quot;border:1px solid black&quot;&gt;&lt;/div&gt;
  
  &lt;script&gt;
  $(document).bind(&quot;mousemove&quot;, function(e){
      $(&quot;#result&quot;).html(&quot;x:&quot; + e.pageX + &quot;, y:&quot; + e.pageY);
  });
      
  $(&quot;#iframe1&quot;).contents().find(document).bind(&quot;mousemove&quot;, function(e){
  $(&quot;#result&quot;, window.parent.document).html(&quot;x:&quot; + e.pageX + &quot;, y:&quot; + e.pageY);
  });
  &lt;/script&gt;
  </code></pre>
  <p>The first <code>mousemove</code> event works correctly displaying the mouse position in the results div, but the second event (which I was attempting to bind to the iframe document) gives no response.​</p>