hello friends,
I wanna know how can I perform copy-paste operations using javascript.
Does anyone have the script for this ? ........ kindly post
thanks a lot...
hello friends,
I wanna know how can I perform copy-paste operations using javascript.
Does anyone have the script for this ? ........ kindly post
thanks a lot...
Sometimes, when the user submits a form you may want to offer him the possibility to copy the content of a field (such as a textarea) to the clipboard so that if something goes wrong he doesn't lose what he just wrote.
Here is the JavaScript code to COPY :
In HTML you need to make this work like this:Code:<script type="text/javascript"> function CopyToClipboard() { CopiedTxt = document.selection.createRange(); CopiedTxt.execCommand("Copy"); } </script>
Code:<form name="Form1"> Here is some text you can copy. You can copy text from anywhere on the page, simply select it and press the Copy to clipboard button. Then you can paste it anywhere you want, in Notepad, Visual Studio or in the textarea below. <br /><br /> <textarea id="txtArea" cols="60" rows="5">You can also copy text from this textarea. Or you can paste the text here, using the Ctrl+V key combination.</textarea> <br /> <input type="button" onClick="CopyToClipboard()" value="Copy to clipboard" /> </form>
To COPY-PASTE:
Here's the JavaScript you need to use for implementing both a copy button and a paste button:
In HTML, you need to make this work like this -Code:<script type="text/javascript"> function CopyToClipboard() { CopiedTxt = document.selection.createRange(); CopiedTxt.execCommand("Copy"); } function PasteFromClipboard() { document.Form1.txtArea.focus(); PastedText = document.Form1.txtArea.createTextRange(); PastedText.execCommand("Paste"); } </script>
Code:<form name="Form1"> Select this text, copy it using the copy button, and paste it below.<br /><br /> <textarea id="txtArea" cols="60" rows="5"></textarea> <br /> <input type="button" onClick="CopyToClipboard()" value="Copy to clipboard" /> <input type="button" onClick="PasteFromClipboard()" value="Paste from clipboard" /> </form>
Bookmarks