Apps Script公式リファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2018年8月15日水曜日

選択した文字列をクリップボードに保存したい(ボタン)


getSelection().toString()

execCommand("copy")

で実現できたので備忘録として



コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
<body>
    <p>あいうえおかきくけこ</p>
    <button id="bt">ボタン</button>
    <script>
        document.getElementById("bt").onclick = get_copy;

        function get_copy() {
          var value = window.getSelection().toString();
          document.execCommand("copy");
        }
    </script>
</body>
</html>
意訳
 


コピー対象の文字列
実行ボタン

実行ボタンをクリックしたらget_copyを実行する
この機能がやること

選択されている文字列を取得して
クリップボードにコピーする






参考

window.getSelection
https://developer.mozilla.org/ja/docs/Web/API/Window/getSelection

document.execCommand
https://developer.mozilla.org/ja/docs/Web/API/Document/execCommand

Latest post

Google Apps Scriptの障害時はIssueTrackerを見てみる - Incidents for Apps Script are reported on Issue Tracker

IssueTracker > Apps Script issues https://issuetracker.google.com/savedsearches/566234 Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが...