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.

mattquantic

Programmer
Mar 28, 2004
196
GB
Hi. I'm having a prob calling a method(?) from the code rather than on an event.

This text box, when clicked will take whatever is in the clip board and paste it in with the content.

Is there any way that I can do this voa code.

For example:
document.getElementById("WordTextst").focus();
document.getElementById("WordTextst").execCommand('Paste');

<textarea name="WordTextst" rows=10 cols=100 id="WordTextst" onclick="execCommand('Paste');">Some

click here

content
</textarea>

Thanks if you can point me in the right direction.

Matt
 
The following method will NOT work in FF:

Code:
var clipboardText = window.clipboardData.getData('Text');
document.getElementById("WordTextst").innerHTML += clipboardText;

Those two lines of code will take what is currently in the clipboard and add it to what already exists in the textarea.

<.

 
Hi. Thanks for aking the time to respond.

Unfortunatly. It needs to use/call the native paste, as it may be half way in the text where the paste needs to go.

Matt

 
Think I may have found it, I'm going to test out what I have real quick though.



<.

 
It's as simple as changing this:
Code:
document.getElementById("WordTextst").execCommand('Paste');

To this:

Code:
document.execCommand('Paste');

Here is the code I tested with:

Code:
<html>
<head>
<script type="text/javascript">
function pasteContent() {
   document.execCommand('Paste');
}
</script>

</head>
<body>
<textarea id="WordTextst" cols="23" rows="20" onclick="pasteContent()">
GOt some skizzit here 
</textarea>
</body>
</html>





<.

 
Hi. Cheers again.

Isn't that the same as my first post?
<textarea name="WordTextst" rows=10 cols=100 id="WordTextst" onclick="execCommand('Paste');"></textarea>

Thanks for your perseverence. I've been trying for 6 hours now...

Matt
 
That isn't the same at all

You need to look at EXACTLY what I have typed

Code:
<textarea name="WordTextst" rows=10 cols=100 id="WordTextst" onclick="[!]document.[/!]execCommand('Paste');"></textarea>

Notice the addition of "[!]document.[/!]"

<.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top