473,508 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting incorrect offsetleft and offsettop values in IE

85 New Member
have a problem with this code when working in IE
it gives me 0,0 coords when i use iframe tag but gives correct coords when using firefox

Expand|Select|Wrap|Line Numbers
  1. function GetRealOffset(id)
  2. {
  3.  
  4.     var elem = document.getElementById(id);
  5.     var leftOffset = elem.offsetLeft;
  6.     var topOffset = elem.offsetTop;
  7.     var parent = elem.offsetParent;
  8.  
  9.         while(parent != document.body) 
  10.     {
  11.              leftOffset += parent.offsetLeft;
  12.          topOffset += parent.offsetTop;
  13.             parent = parent.offsetParent;
  14.     }
  15.         var Offsets = new Object();
  16.     Offsets.top = topOffset;
  17.     Offsets.left = leftOffset;
  18.  
  19.         alert(Offsets.top + " " +Offsets.left)
  20.     return Offsets;
  21. }
i found out some more function and they r all giving me 0,0 coords
i read in a tutorial that IE gives 0,0 coords for all elements unless the page is loaded but i want the offset values when the page is loading coz im putting advertisements in the iframes and some pages can take minutes to load.
All these functions r working fine in mozilla tho
i think what i need it a function to get the correct offset values when the page is loading in IE
Jul 27 '07 #1
2 11059
pbmods
5,821 Recognized Expert Expert
Heya, rohitchawla. Welcome to TSDN!

Check out this article.
Jul 27 '07 #2
kovik
1,044 Recognized Expert Top Contributor
Don't check against document.body, check against whether or not the offsetParent is null or not. The highest element has a null (non-existant) offsetParent.
Jul 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2370
by: Pieter Van Waeyenberge | last post by:
Hello In the code below, theres a DIV, a TABLE and another DIV , each with an image in it. When i read out the offsetLeft/Top from imgB in the table , i get offset values relative to the...
1
2015
by: Weston C | last post by:
Here's something I'm working on: for a click on a given element, I want to be able capture the x/y coordinates of the mouse -- that is, the mouse coordinates relative to the top left corner of said...
21
3931
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
6
16522
by: Seth Illgard | last post by:
Hi. I need to obtain the exact postion of a div. I was using (variable and function names are in spanish, sorry): //Get X position function obtenerPosicionX(elemento) { var x=0;...
1
3623
by: Orion | last post by:
In my code i am trying to access offsetLeft and offsetTop values for a element which is a div, I use offsetParent property to obtain the same. The code i use is this.tip.style.left =...
5
5459
by: montybytes | last post by:
Hi there, Although, I have already placed this question in the HTML/CSS section, perhaps it might be worthwhile asking the question here as well. I have a JavaScript function which retrieves...
3
4900
by: Nitinkcv | last post by:
Hi all, Im trying to do the following: Have 3 divs which are placed side by side. each has a two links 'left' and 'right'. Say on click of the 'left' hyperlink of the 2nd div(middle), the 1st...
4
2365
by: N00b13 | last post by:
I have a great JS menu but I have to update every page each time I want to change a link. Is there a way to store my links in a file and call it so i only change that file? (what I have tried so far...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3195
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.