As shown below:
<script type= "Text/javascript" >
function Jscopy () {
var E=document.getelementbyid ("Contents"); object is Contents
e.select ();//Select Object
document.execcommand ("copy");//Execute Browser copy command
}
</script>
<textarea id= "Contents cols=" rows= "5" ></textarea> <br/> <input
"button" Onclick= "Jscopy ();" value= "Copy"/>
JS replication is nothing but the following three steps:
1, get the copied object: document.getElementById ("contents") This sentence is to obtain the id= "contents" textarea.
2, the contents of the selected object: E.select ()
3. Use the ExecCommand ("") function to copy the content.
The following is a detailed description of the parameters of the ExecCommand ("") function:
1, Format: Document.execcommand (scommand[, interactive mode, dynamic parameters))
2. Detailed Parameters:
1, implementation of the full selection command
[format]:document.execcommand ("SelectAll")
[description] will select all content in the Web page!
2, implementation of the Open command
[format]:document.execcommand (' Open ')
[description] This and VB and other programming design in the WebBrowser control of the command somewhat similar, we can also be pondering.
3, implementation of the Save As command
[format]:document.execcommand ("SaveAs")
[description] Save the page to a different directory on this site!
4, implementation of the Print command
[format]:document.execcommand ("print")
[description] Of course, you have to install the printer!
JS code listed below are instruction parameters and meanings
Equivalent to clicking the Open button in the file Document.execcommand ("open");
Save the current page as Document.execcommand ("SaveAs");
Clips the selected text to the Clipboard;
Document.execcommand ("Cut", "false", NULL);
Delete the selected text;
Document.execcommand ("Delete", "false", NULL);
Change the font of the selected area;
Document.execcommand ("FontName", "false", sfontname);
Change the font size of the selected area;
Document.execcommand ("FontSize", "false", ssize|isize);
Set the foreground color;
Document.execcommand ("ForeColor", "false", scolor);
The object of absolute positioning can be dragged directly;
Document.execcommand ("2d-position", "false", "true");
Make the object positioning into absolute positioning;
Document.execcommand ("AbsolutePosition", "false", "true");
Set the background color;
Document.execcommand ("BackColor", "false", scolor);
Make the text in the selected area bold;
Document.execcommand ("Bold", "false", NULL);
Copy the selected text to the Clipboard;
Document.execcommand ("Copy", "false", NULL);
Sets the specified anchor point as a bookmark;
Document.execcommand ("CreateBookMark", "false", sanchorname);
Turns the selected text into a hyperlink, and the Parameter Settings dialog box appears if the second argument is true;
Document.execcommand ("Createlink", "false", slinkurl);
Sets the label name of the current block;
Document.execcommand ("Formatblock", "false", stagname); Equivalent to clicking the Open button in a file Document.exEccommand ("Open");
Save the current page as Document.execcommand ("SaveAs");
Clips the selected text to the Clipboard;
Document.execcommand ("Cut", "false", NULL);
Delete the selected text;
Document.execcommand ("Delete", "false", NULL);
Change the font of the selected area;
Document.execcommand ("FontName", "false", sfontname);
Change the font size of the selected area;
Document.execcommand ("FontSize", "false", ssize|isize);
Set the foreground color;
Document.execcommand ("ForeColor", "false", scolor);
The object of absolute positioning can be dragged directly;
Document.execcommand ("2d-position", "false", "true");
Make the object positioning into absolute positioning;
Document.execcommand ("AbsolutePosition", "false", "true");
Set the background color;
Document.execcommand ("BackColor", "false", scolor);
Make the text in the selected area bold;
Document.execcommand ("Bold", "false", NULL);
Copy the selected text to the Clipboard;
Document.execcommand ("Copy", "false", NULL);
Sets the specified anchor point as a bookmark;
Document.execcommand ("CreateBookMark", "false", sanchorname);
Turns the selected text into a hyperlink, and the Parameter Settings dialog box appears if the second argument is true;
Document.execcommand ("Createlink", "false", slinkurl);
Sets the label name of the current block; Document.execcommand ("Formatblock", "false", stagname);
Note: Firefox does not support this method!
The above is small series for everyone to bring JS copy content to the Clipboard code, JS copy code Simple example of all the content, I hope we support cloud Habitat Community ~