473,789 Members | 3,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2613
Jay

<gl****@gmail.c om> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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.c om> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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.len gth;
while ( x = arguments[--i] ) {
addSpans(docume nt.getElementBy Id(x));
}
}

function addSpans(t) {
var s, w = t.firstChild.da ta.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.create TextNode(w[i]);
} else {
s = document.create Element('span') ;
s.id = n + '-' + i;
s.appendChild(d ocument.createT extNode(w[i]));
s.onclick = function() {
alert('This is ' + this.id + ', it contains:'
+ '\n' + this.firstChild .data);};
}
t.appendChild(s );
}
}

</script>
</head>
<body onload="addClic ks('p1','p2','p 3')">
<p id="p1">here is some text in a document. It will become
clickable when the page loads.</p>
<p id="p2">Counte r-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.co m 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.tagN ame))
{
rng = document.body.c reateTextRange( );
rng.moveToPoint (e.x, e.y);
rng.expand('wor d');
document.forms[0].t.value += '~ ' + rng.htmlText + '\n';
rng.pasteHTML(' <span class="silver"> ' + rng.htmlText + '</span>');
}
}

document.onclic k = 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:15 0px;height:300p x;overflow:hidd en;">
</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
2659
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 frame/panel to display a Choice. But I would like the Program to not continue on until the user makes their selection from the dropdown/Combo box in the new popup window. Right now, I have it setup so that the Listeners for the main frame are looking...
3
6587
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 the user is prompted to save the file. Any idea how to do this? Thanks, David
0
1065
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 Index Server search engine but some developers are telling us certain things aren't possible or too complicated. I was hoping an expert here could help me determine if we can proceed with an idea we've developed. Basically we would like to use a...
88
12561
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
3004
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. So it seems to me, I need to determine the which item I right clicked over, perform a setselected on the listbox object and then run my right-click menu. (I'd like a right-click to also serve as selection) The originating object is obvioiusly the...
4
8328
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. That word doucment will then be opened and displayed in MS Word. The code I have below doesn't quite work the way I expected it to. First, VB is complaining that the variable readOnly is not declared. How can that be when it is declared as Dim...
2
1428
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 the html doc displayed 5. detect the word clicked by user and compare it to the word in the list / array mentioned in line 2
0
905
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 a word in the html doc displayed 5. detect the word clicked by user and compare it to the word in the list / array mentioned in line 2
1
1683
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 experimenting with the various events, I can find out which cell the user has clicked and whether or not he/she's clicked in the content (i.e. on the content text), but not on the right side arrow button. Can somebody help me out with this?
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.