473,396 Members | 1,997 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,396 software developers and data experts.

Copy images and text to clipboard

Hi.

I have a web page that has images and text. I can carefully select one
image and the on the right of the image and then copy & paste to Word.

Is it possible to make javascript do the same: select the same area
(divided by <div> tag) and copy to clipboard?

So far I succeeded to make the script to copy the area inside <div> but
it was plain html-text.

The idea is to have tha data in clipboard so one can paste it to Word
remaining the layout like it is in html-file.
Here's what I have now in my html-file:

....
<script>
function copyToClipboard()
{
var x=document.getElementById('copythis');
document.form.copyArea.value=x.innerHTML;
y = document.form.copyArea.createTextRange();
y.select();
y.execCommand("Copy");
}
</script>

....

<div id="copythis">
.... image and text in html-table to be copied to clipboard ...
</div>

....

<form name="form">
<input type="button" name="copy" value="Copy to clipboard"
onClick="copyToClipboard()">
<input type="hidden" name="copyArea" value>
</form>

....
Any help is appreciated.

- Risto
Jul 23 '05 #1
4 32177
> Hi.

I have a web page that has images and text. I can carefully select one
image and the on the right of the image and then copy & paste to Word.

Is it possible to make javascript do the same: select the same area
(divided by <div> tag) and copy to clipboard?

So far I succeeded to make the script to copy the area inside <div> but
it was plain html-text.

The idea is to have tha data in clipboard so one can paste it to Word
remaining the layout like it is in html-file.
Here's what I have now in my html-file:

...
<script>
function copyToClipboard()
{
var x=document.getElementById('copythis');
document.form.copyArea.value=x.innerHTML;
y = document.form.copyArea.createTextRange();
y.select();
y.execCommand("Copy");
}
</script>

...

<div id="copythis">
... image and text in html-table to be copied to clipboard ...
</div>

...

<form name="form">
<input type="button" name="copy" value="Copy to clipboard"
onClick="copyToClipboard()">
<input type="hidden" name="copyArea" value>
</form>

...
Any help is appreciated.

- Risto


Please let me know if this is impossible to do with JS.

Jul 23 '05 #2
Risto Heinonen wrote on 10 sep 2004 in comp.lang.javascript:
I have a web page that has images and text. I can carefully select one
image and the on the right of the image and then copy & paste to Word.

Is it possible to make javascript do the same: select the same area
(divided by <div> tag) and copy to clipboard?
Please let me know if this is impossible to do with JS.


It is impossible to proove that it is.

I think so anyway.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #3


Risto Heinonen wrote:
I have a web page that has images and text. I can carefully select one
image and the on the right of the image and then copy & paste to Word.

Is it possible to make javascript do the same: select the same area
(divided by <div> tag) and copy to clipboard?


With IE 5.5/6 on Win you can try it as follows:
var div = document.getElementById('divId');
div.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';

Then you should be able to paste the clipboard content into Word.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
>> I have a web page that has images and text. I can carefully select one
image and the on the right of the image and then copy & paste to Word.

Is it possible to make javascript do the same: select the same area
(divided by <div> tag) and copy to clipboard?

With IE 5.5/6 on Win you can try it as follows:
var div = document.getElementById('divId');
div.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';

Then you should be able to paste the clipboard content into Word.


Thanks, this is exactly what I was looking for!

- Risto
Jul 23 '05 #5

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

Similar topics

0
by: Piotr | last post by:
I need a VBA macro to copy all text from text objects in the igrafx flowcharter Diagram to clipboard or to save it to a text file (in order to count the text I translated). I tried the...
2
by: kris_scheyer | last post by:
Hi, I've searched dozens of forums and websites to find a way to have javascript copy an image I click on into the clipboard of windows. I found a few examples but I couldn't get any of them to...
6
by: Shyguy | last post by:
I want to create two buttons on a form. One would allow the user to Copy the contents of the current records memo field, the other would allow them to print. I set up a report based on the memo...
2
by: Shayne H | last post by:
I am trying to write a method to copy some text to the clipboard, and leave a copy of it there after the application has exited. Sub CopyToClipboard(ByVal value As Object) Dim data As New...
1
by: jvorselaars | last post by:
Does anybody how I can copy several fields into the clipboard. I have copied the code of the following microsoft website: http://support.microsoft.com/support/kb/articles/q210/2/13.asp But...
11
by: sandeepkedlaya | last post by:
Hello, I need to copy images from a folder and copy to a word document. I have done as follows.. but It copies only last image. Can any one of you help me in this.. Private Sub Page_Load(ByVal...
7
by: ahmed222too | last post by:
how can i copy a text file and paste it in a specific path by VB6 code another question how can i create afolder in a specific path by VB6 thank you
2
by: ahmed222too | last post by:
when i use this code to copy a text file and paste it in a specific path: Dim fso As New FileSystemObject fso.CopyFile "C:\Files\file.txt", "C:\Files1\file_copy.txt" this error appear ...
2
by: VickyC | last post by:
Hello, I have a table that I have protected so that users are not able to edit directly into the table. I am wanting the users to click on Edit, which then opens a form, but I need to copy the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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...
0
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...

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.