Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execCommand paste

Status
Not open for further replies.

hunt00

Technical User
Mar 6, 2005
79
US
If i am using trying to copy/paste using the execCommand:

document.execCommand('copy', false, option);
document.execCommand('Paste');

How can i add more strings when paste ?
 

Can you explain what you mean a bit clearer, please?

Dan


The answers you get are only as good as the information you give!

 
My entire script is using execCommand.

For example:
copy: this is an example
paste result: -this is an example-

the "-" is added at the front and end.

Currently, when using the above command, my paste result is: this is an example, without "-", and i am not sure where/how "-" could be added.

Thanks very much, Dan!
 
Here's one way it could be done:
Code:
document.execCommand('Copy');
copied = clipboardData.getData('Text');
document.execCommand('Paste',false,'-' + copied + '-');
 

Or you could do it at the copy stage:

Code:
document.execCommand('copy', false, '-' + option + '-');

Dan


The answers you get are only as good as the information you give!

 
Thanks very much! It works very well.

Is there a way to add the html tag in there?

document.execCommand('Paste',false,'Here it is: ' + document.write('<br><hr color=red height=10 width=2>') + copied );

document.write or document.writeln messed up the paste with only a little red dot.
 
Thanks very much for the right direction. I will try that now. :)
 
Hi, when i try:

var test1 = new String ("Here it is"); alert('5');
var sHTML = "<br><hr height= 5 color=blue width =2>"; alert('6');
test1.insertAdjacentHTML("beforeEnd",sHTML);
alert('7');

got the object error, which is the last line. alert7 didnt show up. Anything i did wrong?
 
Your code is trying to insert HTML into a string. The HTML must be inserted into an element, like a DIV or a TD element. Try this:
Code:
<div id="test2">
Hello
</div>

<script>
var test1 = "Here it is";
alert('5');
var sHTML = "<br><hr height= 5 color=blue width =2>" + test1; 
alert('6');
test2.insertAdjacentHTML("beforeEnd",sHTML); 
alert('7');
</script>
 
i am trying to get the paste execCommand in the div section

document.writeln('<div id="test2">');
window1.document.execCommand('Paste', false, 'Here it is: ' );
document.writeln('</div>');

var test1 = "document.write('window1.document.execCommand('Paste', false, copied)')";
var sHTML = "<br><hr height= 5 color=blue width =2>" + test1;
test2.insertAdjacentHTML("beforeEnd",sHTML);

I got object error. How can i define the execCommand result to make it work here?

Thanks alot!




 
Try this:
Code:
copied = clipboardData.getData('Text');
document.writeln('<div id="test2">');
document.writeln(copied);
document.writeln('</div>');

var sHTML = "<br><hr height= 5 color=blue width =2>" + copied;
test2.insertAdjacentHTML("beforeEnd",sHTML);
 
Thanks, there. I am getting improvement.
There are 2 problems now.

1. The content is copied to a next page, instead of the same page like using execCommand('paste')
2. The <hr> not still now showing height, width, color

I am still trying around now. If u have any idea, please let me try too.

Thanks again for ur help!
 
copied = clipboardData.getData('Text');
document.write('<div id="test2">');
document.write("Here it is: ");
document.write('</div>');
var sHTML ="<hr height= 5 color=blue width =2>" + copied;
test2.insertAdjacentHTML("beforeEnd",sHTML);

The above problem.
1. Entire paste pasted on another page
2. <hr> is showing a blue dot, and on a seperate line.
 
Now i have only 1 problem left: paste to the same page from window1 to window2, instead of a new page.

window1.document.execCommand('Copy');
copied = clipboardData.getData('Text');
document.write('<div id="test2">');
document.write("Here it is: ");
document.write('</div>');
var t1 = "<table><tr><td bgcolor = blue></td>" ;
var t2 = "<td>" + copied + "</td></tr></table>";
var sHTML = t1 + t2;
test2.insertAdjacentHTML("beforeEnd",sHTML);
 
Thanks, superman! I just got it by adding the window name. :-D
 
when testing for the 2nd, 3rd, 4th... time paste, why it is giving object error?!

window2.test2.insertAdjacentHTML("beforeEnd",sHTML);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top