简体   繁体   中英

How can I copy text to the clipboard without flash in HTML5?

On Google Drive , if I try to share a file and I use Google Chrome, this button appears: 按钮复制网址仅在公共文件中出现

Now, if I press "copy link", it will select the textarea down the button. (it is a input type button) here the picture: 在此输入图像描述

And the question is .... How google do to copy ad text/url to te clipboard without using flash (zeroclipboard)? which API of chrome it used? I'm try to inspect this but see only js.

It is not possible to do it without flash as far as I know. However, if you are using Google Chrome and you installed the Drive App(from the webstore) then you give the browser permission to use your copy and paste.

Try clicking on "right click menu" section in this article: google drive help

Basically, you need permission from the browser. If you can't, then trick the user. I once made a canvas which displayed text, and when the user dragged their mouse it would select the corresponding text in an invisible <div> , and when you press Control+C or Cmd+C you are copying the text using the native shortcut, javascript can't mimic these keys.

The best you can do with javascript is to select the text using document.createRange() and leave it to the user to press Control+C or Cmd+C.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM