Home >Web Front-end >JS Tutorial >JS cleverly obtains clipboard data and pastes Excel data_javascript skills
Another method is to use flash, which can avoid browser security restrictions, but there is only a set method in the system class, and it can be accessed in the other clipboard class, but it seems to require the support of the flash10 version.
I searched online and found nothing. I finally thought of checking out how Google Sheets works.
I found that Google Sheet implements Excel's plain text multi-data grid pasting without the need for security restrictions and without using flash. Maybe many people know this method. Anyway, I was surprised at first, but I had no choice but to do it. Google’s js files have been processed and it looks too tiring. Then I went to find the ZOHO sheet. Its js file was simply processed, and I could debug and read it.
It turns out that the onkeydown event is registered on the body. When the user presses the ctrl v key, js shifts the focus to a textarea label, so that the next keyPress and keyUp events occur on the textarea. Naturally, it is equivalent to the user copying it in the textarea, and then js shifts the focus and gets the value from the textarea. In this way, the text data in the clipboard is obtained.
The following is a small example that imitates the implementation of ZOHO sheet.