javascript| Script | Web page
<input type= "button" value= "Copy Test Form" >
<input type= "button" value= "Output the Clipboard contents to the editor" ><BR>
Test
<table border= "1" id= "otable" >
<TR>
<TD> Test Form </TD>
<TD> Test Form </TD>
</TR>
<TR>
<TD> Test Form </TD>
<TD> Test Form </TD>
</TR>
</TABLE> text <BR><BR>
<iframe id= "editor" src= "About:blank" ></iframe>
<script language= "JavaScript" >
<!--
function copytable ()
{
Copyhtmlelement (otable)
}
function copyhtmlelement (obj)
{
Editor.document.designMode = ' on '; Turning an IFRAME into an editable mode, the HTML editor
Editor.document.write ("<body></body>"); Initialize Editor
Editor.document.body.innerHTML = obj.outerhtml;
Editor.document.body.createTextRange (). Select (); Select all contents in the editor
Editor.document.execCommand ("Copy", "", null); Copy
}
function Pastclipboarddata ()
{
Editor.focus ();
Editor.document.execCommand ("Paste", "", null); Paste
}
-->
</SCRIPT>
This function is implemented, but feel a bit uncomfortable, you must use the HTML editor, but from the full selection of HTML editor in the code, notice the createTextRange () method, this method has been useful before, but has not been thoroughly studied. Found in MSDN that only objects such as body, textarea, and so on support the createTextRange () method, continue to be looked up in MSDN, createTextRange () returns a TextRange object, continues to consult TextRange object, found that there are many methods, first tried FindText method, found only text, can not select the object, continue to find, finally found Movetoelementtext is the way we are looking for:
<input type= "button" value= "Checked Test form" >
Test
<table border= "1" id= "otable" >
<TR>
<TD> Test Form </TD>
<TD> Test Form </TD>
</TR>
<TR>
<TD> Test Form </TD>
<TD> Test Form </TD>
</TR>
</TABLE> text
<script language= "JavaScript" >
<!--
function copytable ()
{
var txt = document.body.createTextRange ();
Txt.movetoelementtext (otable);
Txt.select ();
}
-->
</SCRIPT>