If I have a site that holds an iframe:
<html>
<body>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<iframe src="http:/somelink.com/iframe.html"></iframe>
</body>
</html>
Is it then possible for the iframe to know if it can be "seen"? This for example by knowing the top position of the iframe related to the top of the screen.
This is my test iframe: (all values are 0, no matter scroll pos of parent)
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
console.log("ok");
check();
});
function check() {
// position of parent
var parentScrollTop = $(window.parent.document).scrollTop();
console.log("parentScrollTop: "+parentScrollTop);
// self position
var bodyPosition = $("body").position().top;
console.log("body position: "+bodyPosition);
setInterval(check, 1000);
}
</script>
<style type="text/css">
body {
background-color: red;
}
</style>
</head>
<body>
</body>
</html>
I made an image to be more clear.
I have to know from within the iframe if it's visible or not! So not from within the page that holds the iframe.