A js copy and paste event demo, which can be viewed here:
<Html>
<Head>
<Title> JS copy and paste events </title>
</Head>
<Body>
<Input type = "text" id = "text"/>
<Input type = "button" id = "btn" value = "copy"/>
<P> Copy and paste data in the clipboard on the console. </p>
</Body>
<Script type = "text/javascript">
// Obtain and paste data
Document. getElementById ('text'). onpaste = function (e ){
E. preventDefault (); // you can disable default pasting.
Var text = (e. originalEvent | e). clipboardData. getData ('text/plain ');
Console. log (text );
}
// Obtain the copied data
Document. getElementById ('text'). oncopy = function (){
Var text;
If (window. getSelection ){
Text = window. getSelection (). toString ();
} Else if (document. selection & document. selection. createRange ){
Text = document. selection. createRange (). text;
}
Console. log (text );
Alert ('copied successfully, paste it to the desired location ');
}
// Click the Copy button event to search for ZeroClipboard for better compatibility and copy the event using swf.
Document. getElementById ('btn '). onclick = function (){
Document. getElementById ('text'). select ();
Alert ('press CTRL + C or right-click to copy ');
}
</Script>
</Html>
The code for all pages is as follows:
<Html>
<Head>
<Title> JS copy and paste events </title>
</Head>
<Body>
<Input type = "text" id = "text"/>
<Input type = "button" id = "btn" value = "copy"/>
</Body>
<Script type = "text/javascript">
// Obtain and paste data
Document. getElementById ('text'). onpaste = function (e ){
E. preventDefault (); // you can disable default pasting.
Var text = (e. originalEvent | e). clipboardData. getData ('text/plain ');
Console. log (text );
}
// Obtain the copied data
Document. getElementById ('text'). oncopy = function (){
Var text;
If (window. getSelection ){
Text = window. getSelection (). toString ();
} Else if (document. selection & document. selection. createRange ){
Text = document. selection. createRange (). text;
}
Console. log (text );
Alert ('copied successfully, paste it to the desired location ');
}
// Click the Copy button event to search for ZeroClipboard for better compatibility and copy the event using swf.
Document. getElementById ('btn '). onclick = function (){
Document. getElementById ('text'). select ();
Alert ('press CTRL + C or right-click to copy ');
}
</Script>
</Html>