I am trying to display XY coordinates of a PDF file when clicked.
I have referenced a solution found source but still having some issues below
I have two issues:
The code below partly works as it will sometime shows X Y values coordinates when Clicked. Other times it will not work as it will only show X and Y as 0 0 respectively.
The click event only work once. If you try to click the PDF file again no value will be showed unless you refresh the page again. How do I make the click event to show coordinates values each time the PDF file is clicked.
Here is the code:
$(document).ready(function() {
var mouse = {x: 0, y: 0};
document.addEventListener('mousemove', function(e){
mouse.x = e.clientX || e.pageX;
mouse.y = e.clientY || e.pageY
}, false);
$(window).blur( function(e){
console.log("clicked on iframe")
console.log('X: '+ mouse.x);
console.log('Y: '+ mouse.y);
});
$(document).on('mousedown', function(evt) {
console.log('X: '+ evt.pageX);
console.log('Y: '+ evt.pageY);
});
});
Html
<iframe src="test.pdf" width="500" height="900"></iframe>