Home >Web Front-end >JS Tutorial >How does js handle the contents of the clipboard? js method to process the contents of the clipboard

How does js handle the contents of the clipboard? js method to process the contents of the clipboard

云罗郡主
云罗郡主forward
2018-10-22 16:18:322597browse

The content of this article is about how js handles the clipboard? The method of js processing the contents of the clipboard has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

What you need to know before learning this knowledge point is:

Generally, access to the "clipboard" is not allowed on web pages, because this poses a huge security risk

Clipboard access is controllable in IE and FF, but access is not allowed in Opera, Chrome, and Safari browsers, which causes browser compatibility issues

Enter next Main topic:

JavaScript provides the clipboardData object to access the clipboard.

clipboardData provides three methods:

clearData(sDataformat): delete the data in the specified format in the clipboard

setData(sDataformat,sData): assign the specified format to the clipboard Format data, return true if the operation is successful

getData(sDataformat): Get data in the specified format from the clipboard

var text = "123"; 
if (!window.clipboardData.setData('Text', text)) // 赋予 text 格式的数据 
{ 
     alert("复制失败!"); 
} 
text = window.clipboardData.getData('Text'); // 获取 text 格式的数据 
alert(text); 
window.clipboardData.clearData('Text'); // 清除 text 格式的数据 
text = window.clipboardData.getData('Text'); 
alert(text);

The above is how js handles the contents of the clipboard? A complete introduction to the method of js processing the contents of the clipboard. If you want to know more about JavaScript Video Tutorial, please pay attention to the PHP Chinese website.


The above is the detailed content of How does js handle the contents of the clipboard? js method to process the contents of the clipboard. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete