Finding mouse coordinates

P

Pallavi

Hello,

Suppose I want to highlight a piece of text. I get the x & y
co-ordinates on the screen. And using dhtml I am able to highlight the
text. Then I try on another machine with different resolution. I am
unable to get the relative position on the screen. Can anyone guide me
how to find the relative position on different screen resolutions?
Suppose i get the position on 1024 X 768. What would be that position
on 800 X 600 or 640 X 480?

TIA,

Pallavi
 
F

Fabian

Pallavi hu kiteb:
Hello,

Suppose I want to highlight a piece of text. I get the x & y
co-ordinates on the screen. And using dhtml I am able to highlight the
text. Then I try on another machine with different resolution. I am
unable to get the relative position on the screen. Can anyone guide me
how to find the relative position on different screen resolutions?
Suppose i get the position on 1024 X 768. What would be that position
on 800 X 600 or 640 X 480?

iirc, the x position on a 800 pixel wide display, relative to a 1024
pixel wide display, can be found by multiplying by 800/1024. However,
there are many issues associated with using the screen size of the guy
viewing your web page.
 
R

Richard Cornford

Pallavi said:
Suppose I want to highlight a piece of text.

What do you mean by "highlight"? Are you just altering the
presentational style of an element, wrapping some text in a new inserted
element or using the browser's text selection capabilities (where
available)?
I get the x & y co-ordinates on the screen. And using
dhtml I am able to highlight the text.

Do you mean the screen co-ordinates? Usually, for DHTML work, either the
viewport co-ordinates or (more likely) the co-ordinates within the HTML
page are more relevant (as control over the window size and position is
not achievable outside of the controlled environment of an Intranet, and
not always even then).

I don't see a need for knowing the co-ordinates of anything in order to
highlight some text, unless you are using Range objects to select text.
Then I try on another machine with different resolution.
I am unable to get the relative position on the screen.

The relative position of what, and relative to what?
Can anyone guide me how to find the relative position on
different screen resolutions? Suppose i get the
position on 1024 X 768. What would be that position
on 800 X 600 or 640 X 480?

Generally it is possible to write HTML, and the JavaScript to interact
with it, totally independently of screen resolution/window size (indeed
it is advisable to always do exactly that as the page author has no
knowledge or control over either (even when they may believe that they
have)). Unfortunately, it would probably be possible to write a small
book about acquiring and using the relative co-ordinates of HTML
elements, text nodes and pointing devices and that is a bit of an
unrealistic expectation from a Usenet response.

You will have to narrow the subject to what is relevant to you situation
by going to the effort of comprehensively explaining your situation,
probably to the extent of making existing HTML and JavaScript code
available (though that could be just a cut-down version that adequately
demonstrated the problem rather than including code that has no baring).

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top