File: /home/imensosw/www/imenso.co/dev/iframe/index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Detect Click into iFrame</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>
body{
padding: 30px;
}
iframe{
width: 100%;
height: 1100px;
border: 2px solid #ccc;
}
</style>
<script>
$(document).ready(function(){
$("iframe").load(function(){
// $(this).contents().on("mousedown, mouseup, click", function(){
// alert("Click detected inside iframe.");
// });
$(this).contents().on('click1', function(e){
// alert("Click detected inside iframe.");
$(this).scrollTop(880);
e.preventDefault();
$('html, body').animate({
scrollTop : $(this.hash).offset().top
}, 500);
});
});
var myIframe = document.getElementById('iframe');
$(document).on('click','a',function(){
var href=$(this).attr('href');
var test= $('body').find('iframe').contents().find(href).offset().top;
///alert(test);
myIframe.contentWindow.scrollTo({ top: test, behavior: 'smooth' });
})
});
</script>
</head>
<body>
<a href="#new0">About</a> <br>
<a href="#new">ContectUs</a>
<iframe id="iframe" height="100%" width="100%" src="dashboard/faq.html"></iframe>
</script>
</body>
</html>