Get text under the mouse pointer via javascript

View: New views
8 Messages — Rating Filter:   Alert me  

Get text under the mouse pointer via javascript

by Nilanthi Seneviratne :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I was wondering if it is at possible to get the word a user clicks on
with javascript. For example if I click on "word" (note that it isn't
inside a span, div or anchor element), the script would display
"word".

Another way of doing this would be to get the coordinates of the mouse
and find the word which is at that point or the closest word to it.

Is it possible at all? Please help

cheers,

Nilu

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to mochikit@...
To unsubscribe from this group, send email to mochikit-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get text under the mouse pointer via javascript

by Jason Bunting :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I am not thinking hard about this, so if I am way off, someone will correct
me. :P

Seems to me you would have to place just about every word (or, at least,
those you care about) in a span tag and connect to the onmouseover event or
onclick event of that span and then your handler could use scrapeText() to
get the value out.

   connect(oneOfTheSpans, "onclick", function(eventArgs) {
      var textClickedOn = scrapeText(eventArgs.src());
   });

I don't know, there is probably some much better way of doing this, but I
thought I would at least respond.

Jason Bunting


> -----Original Message-----
> From: mochikit@... [mailto:mochikit@...] On
> Behalf Of Nilu
> Sent: Monday, July 07, 2008 9:11 PM
> To: MochiKit
> Subject: [mochikit] Get text under the mouse pointer via javascript
>
>
> Hi,
>
> I was wondering if it is at possible to get the word a user clicks on
> with javascript. For example if I click on "word" (note that it isn't
> inside a span, div or anchor element), the script would display
> "word".
>
> Another way of doing this would be to get the coordinates of the mouse
> and find the word which is at that point or the closest word to it.
>
> Is it possible at all? Please help
>
> cheers,
>
> Nilu
>
> >
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com
> Version: 8.0.138 / Virus Database: 270.4.6/1540 - Release Date: 7/8/2008
> 6:33 AM


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to mochikit@...
To unsubscribe from this group, send email to mochikit-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get text under the mouse pointer via javascript

by Per Cederberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Or using double-click instead of single click. Then the standard text
selection handling applies (not trivial cross-browser, but at least
doable).

Cheers,

/Per

On Tue, Jul 8, 2008 at 6:53 PM, Jason Bunting
<thurber_mingus@...> wrote:

>
> I am not thinking hard about this, so if I am way off, someone will correct
> me. :P
>
> Seems to me you would have to place just about every word (or, at least,
> those you care about) in a span tag and connect to the onmouseover event or
> onclick event of that span and then your handler could use scrapeText() to
> get the value out.
>
>   connect(oneOfTheSpans, "onclick", function(eventArgs) {
>      var textClickedOn = scrapeText(eventArgs.src());
>   });
>
> I don't know, there is probably some much better way of doing this, but I
> thought I would at least respond.
>
> Jason Bunting
>
>
>> -----Original Message-----
>> From: mochikit@... [mailto:mochikit@...] On
>> Behalf Of Nilu
>> Sent: Monday, July 07, 2008 9:11 PM
>> To: MochiKit
>> Subject: [mochikit] Get text under the mouse pointer via javascript
>>
>>
>> Hi,
>>
>> I was wondering if it is at possible to get the word a user clicks on
>> with javascript. For example if I click on "word" (note that it isn't
>> inside a span, div or anchor element), the script would display
>> "word".
>>
>> Another way of doing this would be to get the coordinates of the mouse
>> and find the word which is at that point or the closest word to it.
>>
>> Is it possible at all? Please help
>>
>> cheers,
>>
>> Nilu
>>
>> >
>>
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com
>> Version: 8.0.138 / Virus Database: 270.4.6/1540 - Release Date: 7/8/2008
>> 6:33 AM
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to mochikit@...
To unsubscribe from this group, send email to mochikit-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get text under the mouse pointer via javascript

by Nilanthi Seneviratne :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Jason! :D

It occured to me just after posting it on the group discussion. Now I will figure out a script to convert all the text I need into spans. Unfortunately this might take some time if the document is large. Cheers for confirming my method :)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to mochikit@...
To unsubscribe from this group, send email to mochikit-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get text under the mouse pointer via javascript

by Nilanthi Seneviratne :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


do you by any chance know how to simulate this programmically via
javascript?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to mochikit@...
To unsubscribe from this group, send email to mochikit-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get text under the mouse pointer via javascript

by csnyder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The New York Times does this. Pick any story at http://nytimes.com/
and double-click a word.

It turns out that it's kind of annoying, actually, because it is
unexpected behavior. But that obviously varies case-by-case.

By the way, you shouldn't connect every span to an event. Just connect
the document and then look at event.target() to get the span.

Chris Snyder
http://chxor.chxo.com/

On Tue, Jul 8, 2008 at 1:21 PM, Per Cederberg <cederberg@...> wrote:

>
> Or using double-click instead of single click. Then the standard text
> selection handling applies (not trivial cross-browser, but at least
> doable).
>
> Cheers,
>
> /Per
>
> On Tue, Jul 8, 2008 at 6:53 PM, Jason Bunting
> <thurber_mingus@...> wrote:
> >
> > I am not thinking hard about this, so if I am way off, someone will correct
> > me. :P
> >
> > Seems to me you would have to place just about every word (or, at least,
> > those you care about) in a span tag and connect to the onmouseover event or
> > onclick event of that span and then your handler could use scrapeText() to
> > get the value out.
> >
> >   connect(oneOfTheSpans, "onclick", function(eventArgs) {
> >      var textClickedOn = scrapeText(eventArgs.src());
> >   });
> >
> > I don't know, there is probably some much better way of doing this, but I
> > thought I would at least respond.
> >
> > Jason Bunting
> >
> >
> >> -----Original Message-----
> >> From: mochikit@... [mailto:mochikit@...] On
> >> Behalf Of Nilu
> >> Sent: Monday, July 07, 2008 9:11 PM
> >> To: MochiKit
> >> Subject: [mochikit] Get text under the mouse pointer via javascript
> >>
> >>
> >> Hi,
> >>
> >> I was wondering if it is at possible to get the word a user clicks on
> >> with javascript. For example if I click on "word" (note that it isn't
> >> inside a span, div or anchor element), the script would display
> >> "word".
> >>
> >> Another way of doing this would be to get the coordinates of the mouse
> >> and find the word which is at that point or the closest word to it.
> >>
> >> Is it possible at all? Please help
> >>
> >> cheers,
> >>
> >> Nilu
> >>
> >> >
> >>
> >> No virus found in this incoming message.
> >> Checked by AVG - http://www.avg.com
> >> Version: 8.0.138 / Virus Database: 270.4.6/1540 - Release Date: 7/8/2008
> >> 6:33 AM
> >
> >
> > >
> >
>
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to mochikit@...
To unsubscribe from this group, send email to mochikit-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get text under the mouse pointer via javascript

by Nilanthi Seneviratne :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Actually I need to clarify my question, what i need is a way to get
the text given a point. So for example I can pass in the current
position of the mouse pointer, and then if at that point there is a
word (text) get that word. if not it can return null... Is it possible
at all? Any advice is appreciated. :D

Cheers,

Nilu

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to mochikit@...
To unsubscribe from this group, send email to mochikit-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get text under the mouse pointer via javascript

by amit-29 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Though not tested, following might work...

var getElementsByTagAndPosition = function(tag, cord, context) {

    var context = context || document;

    return MochiKit.Base.filter(function(e){

            var pos = MochiKit.DOM.elementPosition(e);
            var dim = MochiKit.DOM.elementDimensions(e);

            return cord.x >= pos.x && cord.x <= pos.x + dim.w &&
                   cord.y >= pos.y && cord.y <= pos.y + dim.h;

        }, MochiKit.DOM.getElementsByTagAndClassName(tag, null,
context));
});

On Jul 29, 1:38 pm, Nilu <lsen...@...> wrote:
> Actually I need to clarify my question, what i need is a way to get
> the text given a point. So for example I can pass in the current
> position of the mouse pointer, and then if at that point there is a
> word (text) get that word. if not it can return null... Is it possible
> at all? Any advice is appreciated. :D
>
> Cheers,
>
> Nilu

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to mochikit@...
To unsubscribe from this group, send email to mochikit+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price