Someone asked me a question today: How to copy a table on a web page through js script? It seems to be more difficult, but I still got it done. By the way, I recorded the process of solving this problem. I hope it will be helpful to the brothers who write scripts.
I have never written this kind of script before, but I remembered that I saw a script not long ago that can select all the contents of the HTML editor, so I thought of a plan: use a script to insert the table into the HTML editor. Then select all the content in the HTML editor and execute the copy command of the HTML editor to realize the copy table function and get it done quickly:
]
This function is realized , but I feel a little unhappy because I have to use the HTML editor. However, from the code of the HTML editor, I noticed the createTextRange() method. This method has been used before, but I have never studied it in depth. In Msdn, I found that only objects such as Body and TextArea support the createTextRange() method. I continued to check it carefully in msdn. CreateTextRange() returns a TextRange object. I continued to check the TextRange object and found that it has many methods. I gave it a try first. findText method, I found that I could only select text but not objects. I continued to search and finally found that moveToElementText was the method we were looking for:
If you need to introduce external Js, you need to refresh to execute
]