在HTML5中,如何在没有flash的情况下将文本复制到剪贴板上?

时间:2022-08-26 21:33:54

On Google Drive, if I try to share a file and I use Google Chrome, this button appears: 在HTML5中,如何在没有flash的情况下将文本复制到剪贴板上?

在谷歌驱动器上,如果我试图共享一个文件并使用谷歌Chrome,则会出现以下按钮:

Now, if I press "copy link", it will select the textarea down the button. (it is a input type button) here the picture: 在HTML5中,如何在没有flash的情况下将文本复制到剪贴板上?

现在,如果我点击“复制链接”,它会在按钮下面选择textarea。(它是一个输入类型按钮)这里的图片:

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.

问题是....谷歌如何在不使用flash (zeroclipboard)的情况下将广告文本/url复制到te剪贴板?它使用的是哪个API ?我试着检查一下,但是只看到js。

1 个解决方案

#1


5  

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.

据我所知,没有flash是不可能做到的。但是,如果您正在使用谷歌浏览器,并且您安装了驱动器应用程序(来自webstore),那么您将允许浏览器使用您的复制和粘贴。

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.

基本上,您需要浏览器的许可。如果你做不到,那就欺骗用户。我曾经制作了一个显示文本的画布,当用户拖拽鼠标时,它会在一个不可见的

中选择相应的文本,当您按Control+C或Cmd+C时,您正在使用本机快捷方式复制文本,javascript不能模仿这些键。

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.

使用javascript所能做的最好的事情就是使用document.createRange()选择文本,并让用户按Control+C或Cmd+C。

#1


5  

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.

据我所知,没有flash是不可能做到的。但是,如果您正在使用谷歌浏览器,并且您安装了驱动器应用程序(来自webstore),那么您将允许浏览器使用您的复制和粘贴。

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.

基本上,您需要浏览器的许可。如果你做不到,那就欺骗用户。我曾经制作了一个显示文本的画布,当用户拖拽鼠标时,它会在一个不可见的

中选择相应的文本,当您按Control+C或Cmd+C时,您正在使用本机快捷方式复制文本,javascript不能模仿这些键。

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.

使用javascript所能做的最好的事情就是使用document.createRange()选择文本,并让用户按Control+C或Cmd+C。