A
A
Andrey Borchik2018-07-26 22:16:31
css
Andrey Borchik, 2018-07-26 22:16:31

Why is text not being copied in IOS?

I implement the functionality of copying text on the click of a button. Everything works in Chrome on PC but does not work in the mobile version of IOS Safari
What's the problem?

<script type="text/javascript">
function copyToClipboard(element) {
  var $temp = $("<input>");
  $("body").append($temp);
  $temp.val($(element).text()).select();
  document.execCommand("copy");
  $temp.remove();
}
</script>

<p id="p1">Текст,  который надо скопировать</p>

<button class="button--extra" onclick="copyToClipboard('#p1'); document.getElementsByClassName('copied')[0].style.display = 'block';">Скопировать отзыв в буфер</button>
<p style="display: none; text-align: center; margin: 0;" class="copied">Скопировано</p>

Here it is implemented: Arthata.by

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lamer350, 2018-07-27
@andryu6ka

Alas and ah, just use solutions like https://clipboardjs.com
At one time I tried a lot of things, settled on this solution. I copy even tables of several hundred lines, it works on all platforms and in all browsers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question