Reputation: 1579
I want to find the co-ordinates of an iframe relative to the page in which it resides. I am trying to call this iframe from some click event inside it.
The page contains multiple iframes.
Any help will be appreciated.
Upvotes: 1
Views: 76
Reputation: 1579
I think the lack of knowledge on iframes and how frames communicate caused the problem on my part. Well the only way I was able to solve this was to use window.postmessage
to allow cross -origin communication.
https://developer.mozilla.org/en-US/docs/DOM/window.postMessage
Appreciate the help.
Upvotes: 0
Reputation: 30025
Check out http://api.jquery.com/position/ and http://api.jquery.com/offset/, one of these should get you the coordinates you are looking for. As for the click. The click even should bubble to the iframe element of the dom, so you can listen there. Something like this:
$('#myIframe').on('click',function(){
var coordinates = [$(this).offset().top, $(this).offset().left];
});
Upvotes: 2