{"id":35312,"date":"2019-07-11T12:32:39","date_gmt":"2019-07-11T12:32:39","guid":{"rendered":"https:\/\/www.knowband.com\/blog\/?p=35312\/"},"modified":"2019-07-12T15:20:34","modified_gmt":"2019-07-12T05:50:34","slug":"copy-clipboard-javascript","status":"publish","type":"post","link":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/","title":{"rendered":"Copy to clipboard in JavaScript"},"content":{"rendered":"<h2>Objectives of the blog<\/h2>\n<p>After the reading of this blog, you will be able to know how data can be copy to clipboard with help of java script.<\/p>\n<h3>Benefit of copy to clipboard functionality<\/h3>\n<p>In the current web world, it\u2019s all about the user experienced from your site. During our work on any site we copy content from one place and paste at another place. It will be really helpful to the user if a site give a functionality of click to copy. It saves the time and effort of the user to select and copy the content.<\/p>\n<h3>Implementation of copy to clipboard functionality<\/h3>\n<p>Let\u2019s see how we can add this functionality:<\/p>\n<h4>Step 1:<\/h4>\n<p>Create a HTML with a paragraph having some content and button to click. You can use any relevant element instead of paragraph for example textbox, textarea, hidden fields etc.<\/p>\n<pre class=\"brush: actionscript3; gutter: true\">&lt;body&gt;\r\n    &lt;p id=&quot;txt_knoband&quot;&gt;KnowBand boasts of the best in the industry plugins for eCommerce systems and has years of experience working with eCommerce websites.&lt;\/p&gt;\r\n    &lt;button onclick=&quot;onClickCopy()&quot;&gt;Copy Text&lt;\/button&gt;\r\n&lt;\/body&gt;<\/pre>\n<h4>Step 2:<\/h4>\n<p>You will need to create a function onClickCopy() which will copy the data of the paragraph. Function will simply run \u201cdocument.execCommand(&#8220;copy&#8221;)\u201d to copy the data to the clipboard.<\/p>\n<pre class=\"brush: actionscript3; gutter: true\">function copyOnClick() {\r\n    var tempInput = document.createElement(&quot;input&quot;);\r\n    tempInput.value = document.getElementById(&quot;txt_knoband&quot;).innerHTML;\r\n    document.body.appendChild(tempInput);\r\n    tempInput.select();\r\n    document.execCommand(&quot;copy&quot;);\r\n    document.body.removeChild(tempInput);\r\n    alert(&quot;value copied&quot;);\r\n}<\/pre>\n<p>In the last line of the script, we have simply added an alert action to inform the user that the data has been copied.<\/p>\n<p>So finally when you click on the button \u201cCopy Text\u201d, data will be copied to the clipboard and you can simply paste by using CRTL + V.<\/p>\n<p>Related Article: <a href=\"https:\/\/www.knowband.com\/blog\/tips\/how-to-set-cookie-using-javascript\/\" target=\"_blank\">How to set Cookie using JavaScript<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Objectives of the blog After the reading of this blog, you will be able to know how data can be copy to clipboard with help of java script. Benefit of copy to clipboard functionality In the current web world, it\u2019s all about the user experienced from your site. During our work on any site we [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kbui_enabled":"","footnotes":""},"categories":[1111],"tags":[14519,14520,14430,10462],"class_list":["post-35312","post","type-post","status-publish","format-standard","hentry","category-tips","tag-copy-data","tag-copy-data-to-clipboard-in-javascript","tag-copy-to-clipboard","tag-javascript"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Copy to clipboard in JavaScript<\/title>\n<meta name=\"description\" content=\"After reading this blog, you will be able to know how data can be copy to clipboard with help of java script.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Copy to clipboard in JavaScript\" \/>\n<meta property=\"og:description\" content=\"After reading this blog, you will be able to know how data can be copy to clipboard with help of java script.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowband Blog | Ecommerce Modules\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Knowband\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-11T12:32:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-07-12T05:50:34+00:00\" \/>\n<meta name=\"author\" content=\"Sunny Saurabh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@KnowbandPlugin\" \/>\n<meta name=\"twitter:site\" content=\"@KnowbandPlugin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sunny Saurabh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/tips\\\/copy-clipboard-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/tips\\\/copy-clipboard-javascript\\\/\"},\"author\":{\"name\":\"Sunny Saurabh\",\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/#\\\/schema\\\/person\\\/57eba27850520f4c8de3853ee8755a55\"},\"headline\":\"Copy to clipboard in JavaScript\",\"datePublished\":\"2019-07-11T12:32:39+00:00\",\"dateModified\":\"2019-07-12T05:50:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/tips\\\/copy-clipboard-javascript\\\/\"},\"wordCount\":238,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/#organization\"},\"keywords\":[\"copy data\",\"copy data to clipboard in JavaScript\",\"copy to clipboard\",\"JavaScript\"],\"articleSection\":[\"Tips\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/tips\\\/copy-clipboard-javascript\\\/\",\"url\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/tips\\\/copy-clipboard-javascript\\\/\",\"name\":\"Copy to clipboard in JavaScript\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/#website\"},\"datePublished\":\"2019-07-11T12:32:39+00:00\",\"dateModified\":\"2019-07-12T05:50:34+00:00\",\"description\":\"After reading this blog, you will be able to know how data can be copy to clipboard with help of java script.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/tips\\\/copy-clipboard-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.knowband.com\\\/blog\\\/tips\\\/copy-clipboard-javascript\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/tips\\\/copy-clipboard-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Copy to clipboard in JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/#website\",\"url\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/\",\"name\":\"Knowband Blog | Ecommerce Modules\",\"description\":\"Magento, Prestashop, Opencart, Shopify\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/#organization\",\"name\":\"Knowband Blog | Ecommerce Modules\",\"url\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/09\\\/cropped-knowband_logo-v2.png\",\"contentUrl\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/09\\\/cropped-knowband_logo-v2.png\",\"width\":153,\"height\":61,\"caption\":\"Knowband Blog | Ecommerce Modules\"},\"image\":{\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Knowband\",\"https:\\\/\\\/x.com\\\/KnowbandPlugin\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/fr\\\/#\\\/schema\\\/person\\\/57eba27850520f4c8de3853ee8755a55\",\"name\":\"Sunny Saurabh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/10\\\/IMG_20181029_123810-150x150.jpg\",\"url\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/10\\\/IMG_20181029_123810-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/10\\\/IMG_20181029_123810-150x150.jpg\",\"caption\":\"Sunny Saurabh\"},\"description\":\"Sunny Saurabh is an experienced Software engineer in C# and ASP.NET as well as an expert as a PHP developer. He has also expert in database design, server maintenance and security. He has achieved this goal only in the short span of 3yrs and still looking forward to achieving more in the IT industry. He lives in New Delhi and his hobby to write the technical writeups.\",\"url\":\"https:\\\/\\\/www.knowband.com\\\/blog\\\/author\\\/ssaurabh\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Copy to clipboard in JavaScript","description":"After reading this blog, you will be able to know how data can be copy to clipboard with help of java script.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Copy to clipboard in JavaScript","og_description":"After reading this blog, you will be able to know how data can be copy to clipboard with help of java script.","og_url":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/","og_site_name":"Knowband Blog | Ecommerce Modules","article_publisher":"https:\/\/www.facebook.com\/Knowband","article_published_time":"2019-07-11T12:32:39+00:00","article_modified_time":"2019-07-12T05:50:34+00:00","author":"Sunny Saurabh","twitter_card":"summary_large_image","twitter_creator":"@KnowbandPlugin","twitter_site":"@KnowbandPlugin","twitter_misc":{"Written by":"Sunny Saurabh","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/#article","isPartOf":{"@id":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/"},"author":{"name":"Sunny Saurabh","@id":"https:\/\/www.knowband.com\/blog\/fr\/#\/schema\/person\/57eba27850520f4c8de3853ee8755a55"},"headline":"Copy to clipboard in JavaScript","datePublished":"2019-07-11T12:32:39+00:00","dateModified":"2019-07-12T05:50:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/"},"wordCount":238,"commentCount":0,"publisher":{"@id":"https:\/\/www.knowband.com\/blog\/fr\/#organization"},"keywords":["copy data","copy data to clipboard in JavaScript","copy to clipboard","JavaScript"],"articleSection":["Tips"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/","url":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/","name":"Copy to clipboard in JavaScript","isPartOf":{"@id":"https:\/\/www.knowband.com\/blog\/fr\/#website"},"datePublished":"2019-07-11T12:32:39+00:00","dateModified":"2019-07-12T05:50:34+00:00","description":"After reading this blog, you will be able to know how data can be copy to clipboard with help of java script.","breadcrumb":{"@id":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.knowband.com\/blog\/tips\/copy-clipboard-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.knowband.com\/blog\/fr\/"},{"@type":"ListItem","position":2,"name":"Copy to clipboard in JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.knowband.com\/blog\/fr\/#website","url":"https:\/\/www.knowband.com\/blog\/fr\/","name":"Knowband Blog | Ecommerce Modules","description":"Magento, Prestashop, Opencart, Shopify","publisher":{"@id":"https:\/\/www.knowband.com\/blog\/fr\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.knowband.com\/blog\/fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.knowband.com\/blog\/fr\/#organization","name":"Knowband Blog | Ecommerce Modules","url":"https:\/\/www.knowband.com\/blog\/fr\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.knowband.com\/blog\/fr\/#\/schema\/logo\/image\/","url":"https:\/\/www.knowband.com\/blog\/wp-content\/uploads\/2016\/09\/cropped-knowband_logo-v2.png","contentUrl":"https:\/\/www.knowband.com\/blog\/wp-content\/uploads\/2016\/09\/cropped-knowband_logo-v2.png","width":153,"height":61,"caption":"Knowband Blog | Ecommerce Modules"},"image":{"@id":"https:\/\/www.knowband.com\/blog\/fr\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Knowband","https:\/\/x.com\/KnowbandPlugin"]},{"@type":"Person","@id":"https:\/\/www.knowband.com\/blog\/fr\/#\/schema\/person\/57eba27850520f4c8de3853ee8755a55","name":"Sunny Saurabh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.knowband.com\/blog\/wp-content\/uploads\/2018\/10\/IMG_20181029_123810-150x150.jpg","url":"https:\/\/www.knowband.com\/blog\/wp-content\/uploads\/2018\/10\/IMG_20181029_123810-150x150.jpg","contentUrl":"https:\/\/www.knowband.com\/blog\/wp-content\/uploads\/2018\/10\/IMG_20181029_123810-150x150.jpg","caption":"Sunny Saurabh"},"description":"Sunny Saurabh is an experienced Software engineer in C# and ASP.NET as well as an expert as a PHP developer. He has also expert in database design, server maintenance and security. He has achieved this goal only in the short span of 3yrs and still looking forward to achieving more in the IT industry. He lives in New Delhi and his hobby to write the technical writeups.","url":"https:\/\/www.knowband.com\/blog\/author\/ssaurabh\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/posts\/35312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/comments?post=35312"}],"version-history":[{"count":4,"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/posts\/35312\/revisions"}],"predecessor-version":[{"id":40104,"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/posts\/35312\/revisions\/40104"}],"wp:attachment":[{"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/media?parent=35312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/categories?post=35312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.knowband.com\/blog\/wp-json\/wp\/v2\/tags?post=35312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}