Copy images and text to clipboard

R

Risto Heinonen

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
 
R

Risto Heinonen

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.
 
E

Evertjan.

Risto Heinonen wrote on 10 sep 2004 in comp.lang.javascript:
Please let me know if this is impossible to do with JS.

It is impossible to proove that it is.

I think so anyway.
 
R

Risto Heinonen

I have a web page that has images and text. I can carefully select one
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top