HighDots Forums  

get a single word from point(x,y)

Javascript JavaScript language (comp.lang.javascript)


Discuss get a single word from point(x,y) in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dave
 
Posts: n/a

Default get a single word from point(x,y) - 06-02-2008 , 10:34 AM






Hi all,
I have a problem with DOM.

If I have the xy coordinates in a web page, how can I get (possibly
using Javascript) the corresponding word placed into the web page at
the given coordinates?

Thank you.

Reply With Quote
  #2  
Old   
Dan Rumney
 
Posts: n/a

Default Re: get a single word from point(x,y) - 06-02-2008 , 11:28 AM






Quote:
I have a problem with DOM.

If I have the xy coordinates in a web page, how can I get (possibly
using Javascript) the corresponding word placed into the web page at
the given coordinates?
The DOM is the Document Object Model which describes the *structure* of
the document and contains no information about how it is displayed.

The rendering of the document is controlled by the User Agent (generally
a web browser, but could be a screen reader or some other UA). This
renders the document according to its own internal rules and, where
appropriate, according to the associated CSS style-sheets.

If you need to place a word at a specific location, one method would be
to put it in a DIV and then set its style property such that its
positioning is absolute and set its top and left properties accordingly.

Just a word of warning: accessibility is a hot button on this forum.
This kind of functionality is not going to come across on screen readers
and text only browsers and some people take issue with this. Ultimately,
the judgment call is yours, but I would strongly recommend that you look
into the impact of this Javascript on the page's accessibility and make
an informed decision as to whether this is an issue for you.


Reply With Quote
  #3  
Old   
Dan Rumney
 
Posts: n/a

Default Re: get a single word from point(x,y) - 06-02-2008 , 11:35 AM



Quote:
I have a problem with DOM.

If I have the xy coordinates in a web page, how can I get (possibly
using Javascript) the corresponding word placed into the web page at
the given coordinates?
Thinking about this, there are 2 readings:

1) How do I place a word at co-ordinates (x,y) on a visual web page?

2) How do I determine which word is at co-ordinates (x,y) on a visual
web page?

Which are you asking?


Reply With Quote
  #4  
Old   
Dave
 
Posts: n/a

Default Re: get a single word from point(x,y) - 06-02-2008 , 11:54 AM




Quote:
Thinking about this, there are 2 readings:

1) How do I place a word at co-ordinates (x,y) on a visual web page?

2) How do I determine which word is at co-ordinates (x,y) on a visual
web page?

Which are you asking?

It's the second.


Reply With Quote
  #5  
Old   
Dan Rumney
 
Posts: n/a

Default Re: get a single word from point(x,y) - 06-02-2008 , 12:38 PM



Quote:
2) How do I determine which word is at co-ordinates (x,y) on a
visual web page?

Which are you asking?

It's the second.
OK, well there is no way to do that using just the DOM, because of the
description I provided in my previous post.

Also, unless you're using absolute positioning, the location of a
given word will vary according to the size of the page because
paragraph's will wrap according to window width.

Without knowing why you need this functionality (i.e. how it fits in
with your application), it's hard to know what to suggest.

One option would be to wrap your relevant words in a span, each with
an onClick event handler to report that the word has been clicked...
might be appropriate, might not be.

Try http://javascript.internet.com/page-...hted-text.html
for one possible solution


Reply With Quote
  #6  
Old   
Bjoern Hoehrmann
 
Posts: n/a

Default Re: get a single word from point(x,y) - 06-02-2008 , 01:05 PM



* Dave wrote in comp.lang.javascript:
Quote:
If I have the xy coordinates in a web page, how can I get (possibly
using Javascript) the corresponding word placed into the web page at
the given coordinates?
I think only Internet Explorer for Windows offers a simple solution here

var rng = document.body.createTextRange();
rng.moveToPoint(window.event.x, window.event.y);
rng.expand("word");

Getting at least the element should be relatively simple using the semi-
standard document.elementFromPoint(...) method. If you put every word in
its own element that would be sufficient, otherwise narrowing it down to
the word would be a bit tricky.
--
Björn Höhrmann · mailto:bjoern (AT) hoehrmann (DOT) de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.