Skip to content

Instantly share code, notes, and snippets.

@botverse
Created July 24, 2013 11:53
Show Gist options
  • Save botverse/6069885 to your computer and use it in GitHub Desktop.
Save botverse/6069885 to your computer and use it in GitHub Desktop.
Test events inside a iframe with jquery
$(function(){
$("body").mousemove(function(event){
$("#console").html("parent: " + event.pageX + ", " + event.pageY);
});
var iframe = $("<iframe>").load(function(){
iframe.contents().mousemove(function(event){
var position = iframe.position();
$("#console").html("child : " + (event.pageX + position.left) + ", " + (event.pageY + position.top));
});
});
$("body").prepend(iframe)
});
<!DOCTYPE html>
<html>
<head>
<title>Iframe events test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
iframe {
margin: 80px;
}
</style>
</head>
<body>
<div id="console"></div>
<script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
<script src="eventstest.js" type="text/javascript"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment