JS implementation Copy to Pasteboard function

Source: Internet
Author: User

Preface: JS or jquery can be implemented to copy to the Pasteboard function, and sometimes want to have a newline format (with textarea)

Demo

<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><%@ taglib Prefix="C"URI="Http://java.sun.com/jsp/jstl/core"%><HTML><Head>    <title>Test</title></Head><Body>    <ButtonID= "BTN1">Copy custom content to Pasteboard</Button>    <BR/>Box 1<textareaID= "txt"></textarea>    <BR/>    <ButtonID= "BTN2">Copy box 1 contents to Pasteboard</Button>    <BR/>Box 2<textareaID= "Txt3"></textarea>    <ButtonID= "Btn3">Copy box 1 contents to box 2, while to Pasteboard</Button>    <Scripttype= "Text/javascript">window.onload= function(){            functionCopyvalue (val) {//If this is changed to input then line wrapping is not supported                varTemp=Document.createelement ('textarea'); Temp.value=Val;                Document.body.appendChild (temp); Temp.select (); //Select ObjectDocument.execcommand ("Copy"); //perform a browser copy commandTemp.style.display='None'; Console.log ('Replication succeeded'); } document.getElementById ("BTN1"). onclick= function() {Copyvalue ("1234\n copy succeeded \ nthe line was changed .");            }; document.getElementById ("btn2"). onclick= function() {Copyvalue (document.getElementById ("txt"). Value);            }; functionCopyValue2 (val) {varOinput=document.getElementById ('Txt3'); Oinput.value=Val; Oinput.select (); //Select ObjectDocument.execcommand ("Copy"); //perform a browser copy commandConsole.log ('Replication succeeded'); } document.getElementById ("Btn3"). onclick= function() {copyValue2 (document.getElementById ("txt"). Value);        };    }; </Script></Body></HTML>

Note: If you need to support line breaks, you need to use textarea

JS implementation Copy to Pasteboard function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.