Javascript 如何禁止按用户突出显示选择文本,但不允许仅按脚本突出显示选择文本?

Javascript 如何禁止按用户突出显示选择文本,但不允许仅按脚本突出显示选择文本?,javascript,css,google-apps-script,copy,textselection,Javascript,Css,Google Apps Script,Copy,Textselection,我有脚本可以使一些事情相互冲突,使我也困惑解决它。请看下面我的脚本: ============================================================================================================================ -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-u

我有脚本可以使一些事情相互冲突,使我也困惑解决它。请看下面我的脚本:
============================================================================================================================

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
outline-style: none;
user-select: none;
function toClipboard(e) {
  var cell = e.parentNode,
        copyText = cell.getElementsByTagName('span'),
        selection = window.getSelection(),
        range = document.createRange();
    range.selectNodeContents(copyText[0]);
    selection.removeAllRanges();
    selection.addRange(range);
    document.execCommand('copy');
    event.stopPropagation();
}
...
<tr OnClick=highlight(this)>
    <td>test to copy this text <button onclick=toClipboard(this)><small>Copy</small></button></td>
...

以及上面几行的含义,表示用户不允许选择文本。javascript的功能帮助CopyText的进程功能继续运行选择文本,然后将其复制到剪贴板,之后只允许该功能的脚本选择文本。请参见下面的Javascript:
====================================================================================================================================================

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
outline-style: none;
user-select: none;
function toClipboard(e) {
  var cell = e.parentNode,
        copyText = cell.getElementsByTagName('span'),
        selection = window.getSelection(),
        range = document.createRange();
    range.selectNodeContents(copyText[0]);
    selection.removeAllRanges();
    selection.addRange(range);
    document.execCommand('copy');
    event.stopPropagation();
}
...
<tr OnClick=highlight(this)>
    <td>test to copy this text <button onclick=toClipboard(this)><small>Copy</small></button></td>
...

然后运行上述所有脚本的HTML将在表场景中应用。见下文:
===============================================================================================================================

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
outline-style: none;
user-select: none;
function toClipboard(e) {
  var cell = e.parentNode,
        copyText = cell.getElementsByTagName('span'),
        selection = window.getSelection(),
        range = document.createRange();
    range.selectNodeContents(copyText[0]);
    selection.removeAllRanges();
    selection.addRange(range);
    document.execCommand('copy');
    event.stopPropagation();
}
...
<tr OnClick=highlight(this)>
    <td>test to copy this text <button onclick=toClipboard(this)><small>Copy</small></button></td>
...
。。。
测试以复制此文本副本
...


NB:现在的问题是toClipboard的功能不需要工作。我该怎么办?对我的英语感到抱歉,并提前感谢您花时间阅读此帖子

这与应用程序脚本有什么关系?@ziganotschka I实现了这一点,并将其用于htmlService的标记中…尝试新的@TheMaster Hehe。。直到今天我还不知道api的意思是什么???