473,729 Members | 2,331 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 11106
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
2385
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 containng TD ... *as it should be*, HOWEVER, the offsetLeftTop values for imgA/C in the DIVs are calulated realtive to the window border ???? is this normal
1
2033
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 element. So far, here's what I've got: http://weston.canncentral.org/misc/webgallery/Haven/pie.html (Code for the function given in this post below).
21
3984
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 nothing in IE. I'd be greatful for any assistance. Also, if I will have problems the code on Opera or Safari, I'd appreciate any pointers--I don't have a Mac to test Safari. THanks very much, Michael
6
16531
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; while(elemento) { x += elemento.offsetLeft;
1
3665
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 = this.handle.offsetParent.offsetLeft + 'px'; After debugging i found the value of "this.handle.offsetParent" is set to null. I have problems with Mozilla firefox. The code works absolutly fine with IE My questions :-
5
5479
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 the left-position of an Element. This JavaScript functions works in FF and IE7 but does not work in IE6, In IE6 it retrieves the wrong offsetLeft value. Having investigated the problem I noticed it had something to do with the margin-left and position...
3
4909
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 div should take the place of the middle div, while the middle one should take the place of the 1st place. I'm using the prop offsetLeft, however have run into some issues. My code is shown below:
4
2376
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 has not worked, but then again my JS really never works :) ) my .js: if (typeof Scl == "undefined") { var Scl = {}; } (function()
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9281
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
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 we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.