From d33222a6c3fd47d7e9ebf0d7c1c7425a970d093e Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Mon, 26 Jun 2017 11:12:14 -0700 Subject: [PATCH] Copy-to-clipboard fix (#4190) * Copy-to-clipboard fix target.setSelectionRange(0, target.value.length); does not always seem to be working. It doesn't work once the text is unselected. Using textarea.select() function: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select Fixes #3965. Signed-off-by: Ahmet Alp Balkan * Empty commit Signed-off-by: Ahmet Alp Balkan --- js/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/script.js b/js/script.js index d6ff1dacf8..9b9dde3958 100755 --- a/js/script.js +++ b/js/script.js @@ -25,7 +25,7 @@ function copyCode(elem){ } target.value = document.getElementById(elem).innerText; // select the content - target.setSelectionRange(0, target.value.length); + target.select(); // copy the selection var succeed; @@ -520,4 +520,4 @@ $(function() { if (!$('#home').length > 0 ) { $('#hero').addClass('no-sub'); } -}); \ No newline at end of file +});