473,804 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript select text on mouseover

I want to be able to select a word when I highlight over any part of
the word. When I say select the word, I want it to be highlighted as
if I left clicked my mouse and dragged the cursor along the word. I
want to do this so a user when putting the mouse over the word can
quickly hit <ctrl>c to copy the word, without having to manually
highlight the word.

This will be used multiple times in the script for specific words, not
for every word in the script. For example:

User Password
------- ---------------
admin adminUser
dba sysDbAPa$$

So in my above example when mousing over either of the passwords, the
entire password would be highlighted so I can quickly copy it.

Feb 6 '07 #1
3 15483
On Feb 6, 3:09 pm, trp...@gmail.co m wrote:
I want to be able to select a word when I highlight over any part of
the word. When I say select the word, I want it to be highlighted as
if I left clicked my mouse and dragged the cursor along the word. I
want to do this so a user when putting the mouse over the word can
quickly hit <ctrl>c to copy the word, without having to manually
highlight the word.

This will be used multiple times in the script for specific words, not
for every word in the script. For example:

User Password
------- ---------------
admin adminUser
dba sysDbAPa$$

So in my above example when mousing over either of the passwords, the
entire password would be highlighted so I can quickly copy it.
Anyone??? Is this even possible, or has anyone seen this done in the
past?

Feb 8 '07 #2
tr****@gmail.co m wrote:
On Feb 6, 3:09 pm, trp...@gmail.co m wrote:
>I want to be able to select a word when I highlight over any part of
the word. When I say select the word, I want it to be highlighted as
if I left clicked my mouse and dragged the cursor along the word. I
want to do this so a user when putting the mouse over the word can
quickly hit <ctrl>c to copy the word, without having to manually
highlight the word.

This will be used multiple times in the script for specific words, not
for every word in the script. For example:

User Password
------- ---------------
admin adminUser
dba sysDbAPa$$

So in my above example when mousing over either of the passwords, the
entire password would be highlighted so I can quickly copy it.

Anyone??? Is this even possible, or has anyone seen this done in the
past?

It's possible. Your problem is that it's hideously complex and so
doesn't fall into a category that will get an easy answer on the newsgroup.

To give you a starting point here is a script written by Martin Honnen
which will select the contents of any HTML element you pass it. Sample
usage is this..

<pre onClick="select Node(this)">
blah blah blah
</pre>

When you click on the <preelement it will be selected for easy
clipping into the clipboard.

function selectNode (node) {
//This is a third party function written by Martin Honnen
//In comp.lang.javas cript

//http://groups-beta.google.com/group/comp.lang.javas cript/browse_thread/thread/2b389e61c7b951f 2/99b5f1bee9922c3 9?lnk=gst&q=(do c+%3D+node.owne rDocument)+%26% 26+(win+%3D+doc .defaultView)&r num=1&hl=en#99b 5f1bee9922c39
var selection, range, doc, win;
if ((doc = node.ownerDocum ent) && (win = doc.defaultView ) && typeof
win.getSelectio n != 'undefined' && typeof doc.createRange != 'undefined'
&& (selection = window.getSelec tion()) && typeof
selection.remov eAllRanges != 'undefined') {
range = doc.createRange ();
range.selectNod e(node);
selection.remov eAllRanges();
selection.addRa nge(range);
} else if (document.body && typeof document.body.c reateTextRange !=
'undefined' && (range = document.body.c reateTextRange( ))) {
range.moveToEle mentText(node);
range.select();
}
}

That should at least get you started if you want to pursue it from there.

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Feb 8 '07 #3
Thanks! That helped me! Here is how I ended up using it:

<span onmouseover="se lectNode(this)" ;
OnMouseOut="cle arSelection(thi s);">blah</span><br>
<span onmouseover="se lectNode(this)" ;
OnMouseOut="cle arSelection(thi s);">blah1</span><br>
<span onmouseover="se lectNode(this)" ;
OnMouseOut="cle arSelection(thi s);">blah2</span><br>
<span onmouseover="se lectNode(this)" ;
OnMouseOut="cle arSelection(thi s);">blah3</span><br>

<script language=javasc ript>
function selectNode (node)
{
var selection, range, doc, win;

if ((doc = node.ownerDocum ent) && (win = doc.defaultView ) && typeof
win.getSelectio n != 'undefined' && typeof doc.createRange !=
'undefined' && (selection = window.getSelec tion()) && typeof
selection.remov eAllRanges != 'undefined')
{
range = doc.createRange ();
range.selectNod e(node);
selection.remov eAllRanges();
selection.addRa nge(range);
}
else if (document.body && typeof document.body.c reateTextRange !=
'undefined' && (range = document.body.c reateTextRange( )))
{
range.moveToEle mentText(node);
range.select();
}

}
function clearSelection ()
{
if (document.selec tion)
document.select ion.empty();
else if (window.getSele ction)
window.getSelec tion().removeAl lRanges();
}
</script>

So I created an additional function to clear the selection on
OnMouseOut and am using <spantags as the <pretags added an extra
space highlighted at the end of the word, where span does not.
Feb 9 '07 #4

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

Similar topics

2
1187
by: nadie | last post by:
Hello. I do a page thats change de value in a "select" field. whe you put the mouseOver. showing 1 or 2 in the select field. It works well in IE, but only the bottom area of the map changes the value in Netscape. Anybody can help me?. I intend to do a cross browser web. Here is the dir: http://www.academiaforum.com/inmo/borrar.htm Thanks!!!
4
3850
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following beautiful script "http://javascript.internet.com/navigation/toolbar-menu.html". It works like a charm. I made my webpage in frames, where the nav-frame shows the menubar, so whenever I click a link in the menubar, it opens in the frame below. But...
3
2169
by: John Ortt | last post by:
I appologise for reposting this but I have been trying to find a solution all week with no avail and I was hoping a repost might help somebody more knowledgable than myself to spot the message... I am trying to write a webpage in Javascript. The page loads with three frames, a top, left and right frame. Depending on the users actions the background page rewrites the code for the relevant frames.
7
3626
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
13
2378
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
2
2825
by: sgMuser | last post by:
Hi, I am not a good developer of Javascript codes. Needs this help to make some modification to this famous free javascript from Anarchos. i am using this in one of my webpage. What it does is, rotates banners with hyperlink specific to each image. it works just perfect but i need a simple modification. now I want to stop rotating the images when I mouseover on the image, and then continue once I move the cursor out of the banner image....
4
5811
by: =?Utf-8?B?c2lMdmVy?= | last post by:
Hhi, I'm working on an asp .net project that have small side panel which 'disallow' long SELECT/dropdown list.. So i could not force them to a certain that shows my longest option, which now most of my option was being 'cut-off' half way, not able to show to full text.. Is there any way I could do some thing like in e Mozilla FireFox (as currently using IE), which 'opens' e dropdown list when being click and shows e full text that...
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
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...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10096
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...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6866
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3002
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.