clipboardData.setData(format, data)支持的数据类型
根据标准, clipboardData实际上是DataTransfer的一个实例,根据标准定义,setData支持的数据类型只有两种。
参考标准:https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-setdata
The getData(format)
method must run the following steps:
If the
DataTransfer
object is no longer associated with a drag data store, then return the empty string.If the drag data store's mode is the protected mode, then return the empty string.
Let format be the first argument, converted to ASCII lowercase.
Let convert-to-URL be false.
If format equals "
text
", change it to "text/plain
".If format equals "
url
", change it to "text/uri-list
" and set convert-to-URL to true.If there is no item in the drag data store item list whose kind is text and whose type string is equal to format, return the empty string.
Let result be the data of the item in the drag data store item list whose kind is Plain Unicode string and whose type string is equal to format.
If convert-to-URL is true, then parse result as appropriate for
text/uri-list
data, and then set result to the first URL from the list, if any, or the empty string otherwise. [RFC2483]Return result.
The setData(format, data)
method must run the following steps:
If the
DataTransfer
object is no longer associated with a drag data store, return. Nothing happens.If the drag data store's mode is not the read/write mode, return. Nothing happens.
Let format be the first argument, converted to ASCII lowercase.
If format equals "
text
", change it to "text/plain
".If format equals "
url
", change it to "text/uri-list
".Remove the item in the drag data store item list whose kind is text and whose type string is equal to format, if there is one.
Add an item to the drag data store item list whose kind is text, whose type string is equal to format, and whose data is the string given by the method's second argument.
The clearData(format)
method must run the following steps:
If the
DataTransfer
object is no longer associated with a drag data store, return. Nothing happens.If the drag data store's mode is not the read/write mode, return. Nothing happens.
If the method was called with no arguments, remove each item in the drag data store item list whose kind is Plain Unicode string, and return.
Set format to format, converted to ASCII lowercase.
If format equals "
text
", change it to "text/plain
".If format equals "
url
", change it to "text/uri-list
".Remove the item in the drag data store item list whose kind is text and whose type string is equal to format, if there is one.
根据标准可以看到其实现的细节,以及支持的数据类型是:text、url,并且在比较的时候都是先转换为小写。
本文由 微wx笑 创作,采用 署名-非商业性使用-相同方式共享 4.0 许可协议,转载请附上原文出处链接及本声明。
原文链接:https://www.ivu4e.cn/blog/front/2022-10-06/1423.html