复制字段按钮共享点列表

问题描述 投票:0回答:1

如何在 SharePoint Online 列表字段中插入按钮,以允许用户将文本从该字段复制到剪贴板?

sharepoint-online sharepoint-list
1个回答
0
投票

不幸的是,您无法将 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 秒后关闭。不幸的是,这次似乎确实需要。


编辑:请注意,在某些情况下,此解决方案可能非常烦人。实际上,最好的选择是鼓励用户右键单击并选择复制字段。

© www.soinside.com 2019 - 2024. All rights reserved.