Reputation:
how can I get iframe position using JS in the current iframe?
This code works in IE
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
scrollX=self.screenLeft; //works
scrollY=self.screenTop; //works strange
}
How to do it in Firefox?
screenLeft
, screenTop
- undefined
screenX
, screenY
- the position of the parent window
parent.frames[self.name].screenX
- the same result as screenX
Any idea, where is my iframe in FF? Thx.
Upvotes: 1
Views: 2697
Reputation: 29267
You could do this from within the iframe (http://www.quirksmode.org/js/findpos.html)
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curleft,curtop];
}
var topWindow = window.top;
var leftTopPosition = findPos(topWindow.document.getElementById("iframe_id"));
You must specify the iframe's ID, or reference the iframe some other way.
Upvotes: 1