Home  >  Article  >  Web Front-end  >  JS operation clipboard code sharing

JS operation clipboard code sharing

小云云
小云云Original
2018-02-22 15:53:541336browse

Javascript can easily manipulate client clipboard content, but it is only applicable to IE5 and above browsers. JavaScript can handle clipboard contents using the window.clipboardData object. Method setData(param1, param2) to save to the clipboard. This article mainly introduces how to use JS to operate the clipboard function, and shares the example code. Friends who need it can learn from it. I hope it can help everyone.

param1: Data type text or URL, etc.

param2: Data content.

The method of reading data from the clipboard getdata(param1)

The method of clearing data clearData(param1)


  
  
测试操作剪贴板  

  
  
  
  
  

下面是另一个例子实现页面中选中字符,并拖拉到文本区功能。注意其中的window.event.dataTransfer对象也可处理剪贴板内容,不过只能用在 drag-and-drop 操作中。 测试操作剪贴板2

选择我们并把我们拖到下面的textarea

Related recommendations:

Summary of JavaScript methods for copying to the clipboard

HTML5 actual combat and analysis of the clipboard Event

javascript - html5 mobile development, how to copy to the clipboard?

The above is the detailed content of JS operation clipboard code sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn