Determine Position of Object Relative to Page

Determine Position of Object Relative to Page


I am using the eventObj.x and eventObj.y to obtain the position of a link when the mouse is over it to determine where to show a help text box. In Netscape and Internet Explorer 4, the eventObj.y returns the number of pixels the object is from the top of the page. Therefore, if it were 50 pixels from the top, it stayed consistent no matter where I scrolled to on the page.

But in IE5, it was not working, so I used the alert box to return the value when the mouse moved over the object. If I scrolled on the page so the link object was at the top edge of the visible window, then it returned a low number (2, 3, and so on). If I scrolled down, the number increased. So the position where the text help box appeared changed depending on where the window was scrolled to, instead of appearing next to the link each time.

Is this a flaw in IE5, or does IE5 have another way to determine the x and y position relative to the page? In other words, in IE5, it appears that eventObj.y returns the number of pixels that the link is from the top of the visible window, not of the Web page itself.


Navigator and IE both support x and y in relation to a page object, but its meaning and hence its value do differ between the two browsers. Both support x and y to mean an object’s position relative to the object’s container?and there’s where your differences can occur.

If you want to get a position for an object relative to the page, you need to use different properties based on browser type. If you want to capture the object’s left and top position (x and y) for IE, then I suggest you use the clientX and clientY values. If you want to capture the link’s left and top position for Navigator, then you should consider using pageX and pageY. The x and y values you are using are the x and y position of the object relative to the containing layer?they’re really layerX and layerY. If the link is within a positioned DIV block, you would not get an accurate position of the object relative to the page. If you use pageX and pageY, you should get values relative to the browser page.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as