Well guys, i was just doing a simple stuff of executing system copy, delete etc. commands using execCommand method of js.
I have made two textareas and by hitting on the buttons i am executing copy, cut etc. commands.
Problems:
-
In this the paste button is not working. Like i am copying some text from one textarea, it is not pasting into other textarea.
-
Also I want to do select all for the textareas only. Like if cursor is on textarea1 and if I am hitting on selectAll button it should only select the textarea1 content. Currently it is selecting the whole page content.
Code:
<script language="javascript">
function doCopy()
{
document.execCommand('Copy',false,0);
}
function doPaste()
{
document.execCommand('Paste');
}
function doCut()
{
document.execCommand('Cut',false,0);
}
function doSelectAll()
{
document.execCommand('SelectAll',false,0);
}
function doDelete()
{
document.execCommand('Delete',false,0);
}
function doUndo()
{
document.execCommand('Undo',false,0);
}
function doUnselect()
{
document.execCommand('Unselect',false,0);
}
</script>
</head>
<body>
<div align="center">
input values : ---- <br>
<textarea align="left" id="txtArea" name="txtArea" style="width:300px; height:50px"></textarea>
<br>
<input type="button" id="btnCopy" name="btnCopy" value=" Copy " onclick="doCopy()" />
<input type="button" id="btnCut" name="btnCut" value=" Cut " onclick="doCut()" />
<input type="button" id="btnSelectAll" name="btnSelectAll" value=" Select All " onclick="doSelectAll()" />
<input type="button" id="btnPaste" name="btnPaste" value=" Paste " onclick="doPaste()" />
<input type="button" id="btnDelete" name="btnDelete" value=" Delete " onclick="doDelete()" />
<input type="button" id="btnUndo" name="btnUndo" value=" Undo " onclick="doUndo()" />
<input type="button" id="btnUnselect" name="btnUnselect" value=" Undo " onclick="doUnselect()" />
<br>
Manipulate <br>
<textarea align="left" id="txtArea1" onpaste="alert('yes');" name="txtArea1" style="width:300px;height:70px" ></textarea>
</div>
I am doing this for IE9.
I had to make major changes I hope it will be OK for you.
This solution requires jquery. I have tested it with Chrome and Firefox but I dont have IE9.
Here is the example.