•
•
•
•
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
![]() |
•
•
Join Date: Apr 2004
Location: in a galaxy far far away :)
Posts: 121
Reputation:
Rep Power: 5
Solved Threads: 0
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
"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
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation:
Rep Power: 5
Solved Threads: 47
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.
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.
•
•
Join Date: Apr 2004
Location: in a galaxy far far away :)
Posts: 121
Reputation:
Rep Power: 5
Solved Threads: 0
•
•
•
•
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>
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation:
Rep Power: 5
Solved Threads: 47
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.
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.
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation:
Rep Power: 5
Solved Threads: 47
•
•
•
•
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>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.
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
W. C. Fields
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Hover Image Position ??? (HTML and CSS)
- Website NOT showing menu hover in Internet Explorer (Site Layout and Usability)
- Text Not Showing up in IE, Fine in Firefox * NS (JavaScript / DHTML / AJAX)
- CSS compatibility and Menu appearance ??? (HTML and CSS)
- a funny website of mine (Website Reviews)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Background question
- Next Thread: Physics ball JAVASCRIPT



Linear Mode