473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Is it possible to determine the word the user clicked on

Hello,

Anyone that can think of a way to programmaticaly determine the word on
an HTML page that the user clicked on will be my hero for life.

Leo

Jul 23 '05 #1
3 2590
Jay

<gl****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hello,

Anyone that can think of a way to programmaticaly determine the word on
an HTML page that the user clicked on will be my hero for life.


wouldn't each word have to be inside a container in order to get an event to
fire? say a <div> or a <a href>
You could put each word in a <href> and give it a name attribute. Hope you
don't have too many words!
You could change the text to not be link colour, not be underlined and not
change the cursor using CSS.

You could then find out which word was clicked based on the "name"

Jay
Jul 23 '05 #2
Jay wrote:
<gl****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hello,

Anyone that can think of a way to programmaticaly determine the word on
an HTML page that the user clicked on will be my hero for life.

wouldn't each word have to be inside a container in order to get an event to
fire? say a <div> or a <a href>
You could put each word in a <href> and give it a name attribute. Hope you
don't have too many words!
You could change the text to not be link colour, not be underlined and not
change the cursor using CSS.

You could then find out which word was clicked based on the "name"


If attempting this, <span> would likely be a better element to use as
its effect on styles is more neutral while providing similar
functionality (it can be given an id and onclick).
Here is some play code that puts a <span> around each word, gives it
an ID and an onclick function. Note that it totally screws any
internal markup, but that could be fixed with a better parsing
algorithm - the script just splits on word boundaries, then when
putting stuff back in it only adds spans & onclicks to things that
contain only word characters.

Have fun.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Every word clickable </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function addClicks(){
var x, i=arguments.length;
while ( x = arguments[--i] ) {
addSpans(document.getElementById(x));
}
}

function addSpans(t) {
var s, w = t.firstChild.data.split(/\b/);
var n = t.id;
while (t.firstChild && t.removeChild(t.firstChild));
for (var i=0, len=w.length; i<len; i++){
if ( /\W/.test(w[i]) ) {
s = document.createTextNode(w[i]);
} else {
s = document.createElement('span');
s.id = n + '-' + i;
s.appendChild(document.createTextNode(w[i]));
s.onclick = function() {
alert('This is ' + this.id + ', it contains:'
+ '\n' + this.firstChild.data);};
}
t.appendChild(s);
}
}

</script>
</head>
<body onload="addClicks('p1','p2','p3')">
<p id="p1">here is some text in a document. It will become
clickable when the page loads.</p>
<p id="p2">Counter-measure 63 shows that hyphenated words are
a bother, they get split in two as do decimal numbers like
8797.9879.</p>
<p id="p3">Any HTML markup <b>really</b> makes a mess</p>
</body>
</html>
--
Rob
Jul 23 '05 #3

gl****@gmail.com wrote:
Hello,

Anyone that can think of a way to programmaticaly determine the word on an HTML page that the user clicked on will be my hero for life.

Leo


Not that hard in IE, using a textRange...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">

body {
font: normal 14px "comic sans ms";
color: darkred;
}
..silver {
background: silver;
}

</style>
<script type="text/javascript">

function grabword(e)
{
var tgt;
if ((e = e || window.event)
&& (tgt = e.srcElement || e.target)
&& !/((^A$)|(INPUT))/i.test(tgt.tagName))
{
rng = document.body.createTextRange();
rng.moveToPoint(e.x, e.y);
rng.expand('word');
document.forms[0].t.value += '~ ' + rng.htmlText + '\n';
rng.pasteHTML('<span class="silver">' + rng.htmlText + '</span>');
}
}

document.onclick = grabword;

</script>
</head>
<body>
Anyone that can think of a way to programmaticaly determine the word on
an HTML page that the user clicked on will be my hero for life.
<form>
<textarea name="t" style="width:150px;height:300px;overflow:hidden;">
</textarea>
</form>
</body>
</html>

Another matter elsewhere. See if this helps:

http://www.faqts.com/knowledge_base/...html/aid/33674

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rich Wahl | last post by:
I am writing a personal application that uses windowListeners, ActionListeners and possible ItemListeners (combo boxes). I have one of the Buttons (ActionListeners) set to have a popup...
3
by: David Alyea | last post by:
I am writing pages that have hrefs to Word docs and Excel files. I'd like the link to function so that when it is clicked on in IE, instead of the browser showing the Word or Excel document that...
0
by: JakeS | last post by:
Hi there, I work for a municipal Government in Canada and we are having great difficulty getting a high quality web search implmented on our 8,000 page web site. We are trying to refine our...
88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
1
by: akameswaran | last post by:
I have a list box, I'd like to generate a right click menu for items in the list box. The problem is unless I left click the item first, I can't figure out which item in the list I clicked over. ...
4
by: Charlie Brookhart | last post by:
I am trying to write a code for a button click event. When the button is clicked, it is supposed to bring up an open file dialog box to allow the user to select the document they which to open....
2
by: donkeybreath | last post by:
1. Load a html document into flash 2. add words from this html doc to an array or list by clicking on them 3. High lite these words one at a time with events 4. signal user to click on a word in...
0
by: donkeybreath | last post by:
1. Load a html or pdf document into vb 2. add words from this html or pdf doc to an array or list by clicking on them 3. High lite these words one at a time with events 4. signal user to click on...
1
by: JB | last post by:
Hi Everyone, I have a DataGridView with Combo Boxes in its cells. I'd like to know if the user has clicked on the right side arrow button that triggers the opening of the drop down list. After...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.