Link to home
Start Free TrialLog in
Avatar of JR
JR

asked on

How to execute the command Ctrl + C in Javascript

How to execute the command Ctrl + C in Javascript for a text box
Avatar of Naitik Gamit
Naitik Gamit
Flag of India image

Look at this solution for Ctrl+c, Ctrl+v using javascript on textbox:

http://forums.asp.net/t/1816320.aspx?Ctrl+c+Ctrl+v+not+working+on+textboxes
Avatar of JR
JR

ASKER

Need to trigger the Ctrl+C command in Javascript
Hi,

Please try below code (also attached demo HTML file):
<!DOCTYPE html>
<html>
<head>
<title></title>

<script type="text/javascript">

function copyText()
{
	var copied = txt.createTextRange();
	copied.execCommand("Copy");
}

</script>


</head>
<body>

<input type="text" id="txt" />
<input type="button" id="btn" onclick="copyText();" value="Copy Text !!" />

</body>
</html>

Open in new window


Please refer this article for more details.


Hope this helps.

Regards,
Ronak

test9.html
Avatar of JR

ASKER

@Ronak, Thanks.

This works only in IE. Any other way that will work in all browsers other than flash support.
ASKER CERTIFIED SOLUTION
Avatar of Rikin Shah
Rikin Shah
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Please refer this if you can find any work around : Selection and range methods in JavaScript


Regards,
Ronak