如何在 SharePoint Online 列表字段中插入按钮,以允许用户将文本从该字段复制到剪贴板?
不幸的是,您无法将 JavaScript 添加到 Sharepoint 列表。因此,作为替代方案,您必须将用户发送到可以设置剪贴板的自定义网页。
以下 JSON 格式正是这样做的:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"attributes": {
"iconName": "Copy",
"target": "_blank",
"class": "ms-borderColor-white ms-borderColor-themePrimary--hover",
"href": "='https://sancarn.github.io/copy-to-clipboard/index.html?copy=' + @currentField"
},
"style": {
"color": "#272727",
"text-decoration": "none",
"font-size": "14px",
"border-bottom-width": "1px",
"border-bottom-style": "solid",
"min-width": "400px"
},
"children": [
{
"elmType": "span",
"txtContent": "@currentField",
"style": {
"padding-left": "5px"
}
}
]
}
这将添加一个复制图标,如下所示:
单击链接将带您访问 github 上托管的自定义开源网站,我将字段中的文本复制到剪贴板。
示例:https://sancarn.github.io/copy-to-clipboard/index.html?copy=hello%20world
从共享点打开时,窗口将在填充剪贴板后 1 秒后关闭。不幸的是,这次似乎确实需要。