テキストエリア内で選択したテキストを取得したくて書いたコードです
window.getSelection() と onmouseup を使って、テキストを選択した時に
そのテキストを取得してアラートに出してみます
デモ
入力したテキストを選択するとアラートに表示します
コード.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile("index");
}
|
意訳この機能がやること 指定したHTMLファイルを表示する |
index.html
<!DOCTYPE html>
<html>
<body>
<textarea id="ta"></textarea>
<script>
var ta = document.getElementById("ta");
ta.onmouseup = ta_onmouseup;
function ta_onmouseup(){
var selection = window.getSelection();
alert(selection);
}
</script>
</body>
</html>
|
参考
Window.getSelection()
https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection
element.onmouseup
https://developer.mozilla.org/ja/docs/Web/API/GlobalEventHandlers/onmouseup
Window.getSelection()
https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection
element.onmouseup
https://developer.mozilla.org/ja/docs/Web/API/GlobalEventHandlers/onmouseup