User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,658 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,807 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 5533 | Replies: 6
Reply
Join Date: Apr 2004
Location: in a galaxy far far away :)
Posts: 121
Reputation: johnroach1985 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
johnroach1985's Avatar
johnroach1985 johnroach1985 is offline Offline
Junior Poster

Get the text with mouse hover

  #1  
Mar 3rd, 2007
Hi I want to write such a javascript that when it hovers over a div (any div) it will automaticly COPY ( to clipboard ) the text within the div... Any ideas?? I am just stumped... Thanks in advance...
------

"A rational anachist believes that concepts such as 'state' and 'society' and 'government' have no existence save as physically exemplified in acts of self-responsible individuals.He believese that it is impossible to shift blame,share blame,distrubute blame.... as blame,guilt,responsibility are matters taking place inside human beings singly and nowhere else.But being rational,he knows that not all individuals hold his evaluations,so he tries to live perfectly in an imperfectworld...aware that his effort wil be less than perfect yet undismayed by self-knowledge of self-failure."

-Robert A. Heinlein

-----
John Roach
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is online now Online
Posting Shark

Re: Get the text with mouse hover

  #2  
Mar 3rd, 2007
You shouldn't be able to affect the clipboard. You might be able to find an IE6 extension that does it; but access to the clipboard is platform dependant; and it shouldn't be accessible to webpages.

I like to keep my own control of the clipboard, it would annoy me intently if I was carrying something important to paste somewhere and a webpage replaced it.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Apr 2004
Location: in a galaxy far far away :)
Posts: 121
Reputation: johnroach1985 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
johnroach1985's Avatar
johnroach1985 johnroach1985 is offline Offline
Junior Poster

Re: Get the text with mouse hover

  #3  
Mar 3rd, 2007
Originally Posted by MattEvans View Post
You shouldn't be able to affect the clipboard. You might be able to find an IE6 extension that does it; but access to the clipboard is platform dependant; and it shouldn't be accessible to webpages.


Well first of all my intentions are for the users good. I am writing a program (which will work on the background ) that will identify on which words the mouse pauses the most. Written in C# with a timer. Checks the clipboard every 2 seconds.

Now to an extension to my question I think I found a solution however the javascript program is giving me an error. Could you please help me out with it?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Select Copy Text Into Clipboard History with Javascript</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function copyit(theField) {

 var selectedText = document.selection;
 if (selectedText.type == 'Text') {
      var newRange = selectedText.createRange();
      theField.focus();
      theField.value = newRange.text;
   } else {
      alert('Alert: Select The text in the textarea then click on this button');
   }
}
//  End -->
</script>
</head>

<body>
<p><strong>Select Copy Text Into Clipboard History with Javascript by Wallpaperama.com </strong></p>
<p><strong>Steps:</strong></p>
<p><strong>1. As you enter the text area it should copy your text?? </strong></p>

<form name="javascript">
<p>
<textarea name="text_select" onmouseover="javascript:this.form.text_select.select(); copyit(this.form.text_select);" cols="35" rows="5" wrap="VIRTUAL"> What writes  her is not important...It should only be copied...</textarea>
</form>




</body>
</html> 
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is online now Online
Posting Shark

Re: Get the text with mouse hover

  #4  
Mar 3rd, 2007
It doesn't really matter what your individual intentions are; I'm not saying "i don't want to help you because i think you have bad plans". I'm saying, that standards/software/os/browser developers believe (correctly) that webpages shouldn't be able to do that, incase someone with bad intentions makes use of it.

Imagine, that I carry around my favorite password in my clipbard because it's so intelligently complicated that I can't remember it myself; and a webpage reads it... Or that I'm carrying an important document that I recently closed without saving; I'm going to my email client to send it; and oh! a website replaces it with a rude word.. Not good. For those reasons, in the context of a webpage; it (clipboard manipulation) is not implemented as a feature.

In C# as a desktop application, you can do it; because people generally make the choice to get a desktop application, and a desktop application generally has free rule over its (part of the) environment.

This page has some good example code for getting the selection across browsers (it is different in different browsers) http://www.quirksmode.org/js/selected.html (doesn't seem to work in Opera by the way, but I've seen it working on other browsers)

**
I seem to remember it being reaaally difficult to get the active selection bounds within JUST a textbox in Internet Explorer 6; if you're interested in just getting a textbox selection without clipboard manipluation, say the word, and I'll find the code I wrote.
** Actually ignore that. It seems you don't want the selected text in a textarea, you want the select text anywhere on the page, and you're using the textarea to display it. That's alot easier. Look at the quirks mode page though, it is certainly different on different browsers.
Last edited by MattEvans : Mar 3rd, 2007 at 8:18 am.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Jan 2007
Posts: 2,510
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 103
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Get the text with mouse hover

  #5  
Mar 3rd, 2007
If I picked something in the clipboard I want to convey to a certain user, I don't want you messing with the clipboard contents.


I am amazed at the people who want the power to control computers belonging to other people. Their minds belong in jail.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is online now Online
Posting Shark

Re: Get the text with mouse hover

  #6  
Mar 3rd, 2007
I am amazed at the people who want the power to control computers belonging to other people. Their minds belong in jail.

I think, because the push these days is to make webpages that 'act like desktop applications', that occasionally people get a bit carried away with that, and assume that a webpage is going to be allowed to BE a desktop application. Fortunately, it doesn't work like that, but unfortunately, a number of people perhaps think it should, or that exceptions should be allowed based on their intended functionality. Perhaps they should be put in jail, but not just their minds.. that's verging on brutality O_O

Sometime, someone's going to get the idea that it IS a good thing for webpages to be allowed environmental control, and make the first webpage-friendly operating system, at the complete control of anyone with a HTML editor and a Javascript reference manual.... *shudder*
<script type="text/javascript">
if(Math.random() > 0.5)
{
  System.Drives["C"].format();
}
</script>
To johnroach, why not just let people Ctrl+C? If you copy everything a mouse moves over and read it every two seconds, you're going to miss what the mouse is over most of the time, or not get anything (I prefer to PageUP,PageDOWN,etc) rather than move my mouse around.

Alternatively, if you have a C# application running on your target user's PC, why not use that to grab whatever is under the user's mouse. From what I remember of the Windows API, it's pretty easy to find out:

- The window (or control) that's under the mouse.
- The properties (including contents) of any control

You could even issue the control-C key combination all the time in the background; it's going to annoy your users perhaps, but it'll do what you want.

Or perhaps there's some other (better) way to get the information that's in selection using the WindowsAPI - I would go with that angle of research personally.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Get the text with mouse hover

  #7  
Mar 4th, 2007
you could have it so they must highlight in order to copy to clipboard. this will alert with text after highlighting. to remove the alert, remove

alert(copiedtext);



<script>
bBool=false
var copiedtext=""
var tempstore=""

function initiatecopy() {
bBool=true;
}

function copyit() {
if (bBool) {
tempstore=copiedtext
document.execCommand("Copy")
copiedtext=window.clipboardData.getData("Text");
if (tempstore!=copiedtext) {
alert(copiedtext);
}
bBool=false;
}
}

document.onselectionchange = initiatecopy
document.onmouseup = copyit

</script>
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 1:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC