0

I want to get mouse position from an IFRAME that contains a HTML page . But before Iframe HTML page load , this code work nice . After loading Iframe HTML page , this code don't work ! Here is my code :

    <!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="utf-8" />
<style>
#divid {
  height: 600px;
  width: 300px;
  border: 2px solid black;
  transform: scale(0.5, 0.5);
}

</style>
</head>
<body>

<iframe id="iframe" src="http://www.google.com/" >
</iframe>



<script
              src="http://code.jquery.com/jquery-3.3.1.js"
              integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
              crossorigin="anonymous"></script>
<script>
var iframepos = $("#iframe").position();

$('#iframe').contents().find('html').on('mousemove', function (e) {
    var x = e.clientX + iframepos.left;
    var y = e.clientY + iframepos.top;
    console.log(x + " " + y);
})
    </script>

</body>
</html>

can you help me please ?

  • check this link https://stackoverflow.com/questions/12884219/how-can-i-access-an-iframes-document-event-mouse-position-from-the-parent-window – John Rajan Feb 13 '18 at 17:47
  • I use this but don't work . – morteza jamali Feb 13 '18 at 18:20
  • Refer this https://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame Refer this too https://stackoverflow.com/questions/5261328/receive-mousemove-events-from-iframe-too – John Rajan Feb 14 '18 at 06:52

0 Answers0