Wed. Oct 16th, 2019

Codes

Codes for Coders

Javascript Copy to Clipboard by Rishap Gandhi

1 min read
Javascript JQuery Copy to clipboard by Rishap Gandhi

Javascript JQuery Copy to clipboard by Rishap Gandhi

Javascript JQuery Copy to clipboard by Rishap Gandhi
Javascript JQuery Copy to clipboard by Rishap Gandhi

In this blog I will tell you how to create simple clipboard by using javascript.

Firstly we will create a simple html. Containing a textarea and button to copy.

We are taking textarea to enter any text that you want to copy in the clipboard.

Button will be used to click copy the text written in the textarea.

Sample code for the HTML.

<html>
<head>
<title>
Create Code from JQuery by Rishap Gandhi
</title>
</head>
<body>
Enter Any Text in Textarea and Click copy button to copy the text.<br>
<textarea id="textcopy"></textarea>
<input type="button" id="btnSearch" value="Search" onclick="copyToClipboard();" />
</body>
</html>

 

Now next step is to create the Javascript code to copy the text to clipboard.

There is a javascript command document.execCommand(“copy”); to copy thing on the clipboard. So we are going to use this command.

So here is the below javascript code to copy the text:

function copyToClipboard()
{
var aux = document.getElementById("textcopy").value;
document.getElementById("textcopy").setAttribute("value", document.getElementById("textcopy").innerHTML);
document.getElementById("textcopy").select();
document.execCommand("copy");
}

Download Code by Rishap GandhiCompress and Resize of Image in PHP by Rishap Gandhi

Leave a Reply

Your email address will not be published. Required fields are marked *