Friday, October 28, 2022

Copy to Clipboard using Javascript

 Copying the text to clipboard makes it easier to use the web page, so users will definitely like this functionality. You can achieve it using JavaScript.

Note: For this function to work in production environment, make sure your website has SSL Certificate


  <asp:Button ID="btnCopyResult" Visible ="false"   OnClientClick="CopyToClipBoard();"   class="btn btn-primary btn-sm"   runat="server" Text="Copy Result" />  

 <script type="text/javascript">

  function CopyToClipBoard()


var sData = "Copy ME!";




     return true;


 catch (err) 


    alert('Could not write to clipboard', err);

    return false;



No comments:

Post a Comment

Generate Random Numbers in .NET6

 We can generate random number using the following code: Console.WriteLine("Generate Randoms!"); var objRandom = new Random(); var...