Drukowana wersja tematu

Kliknij tu, aby zobaczyć temat w orginalnym formacie

Forum PHP.pl _ JavaScript _ CopyToClipboard() nie działa

Napisany przez: DNMX 5.07.2022, 02:12:47

Hej. Mam taką funkcję:

Kod
<script>
function CopyToClipboard(id)
{
var r = document.createRange();
r.selectNode(document.getElementById(id));
window.getSelection().removeAllRanges();
window.getSelection().addRange(r);
document.execCommand('copy');
window.getSelection().removeAllRanges();
}
</script>

O ile dobrze działa to na takim kodzie:
  1. <http://december.com/html/4/element/a.html href="#" onclick="CopyToClipboard('domain-4');return false;"><http://december.com/html/4/element/i.html class="fas fa-copy"></http://december.com/html/4/element/i.html></http://december.com/html/4/element/a.html>
  2. <http://december.com/html/4/element/a.html target="_blank" href="http://https://domain.com/" id="domain-4">https://domain.com&nbsp;<http://december.com/html/4/element/i.html class="fas fa-external-link-alt"></http://december.com/html/4/element/i.html></http://december.com/html/4/element/a.html>

to na inputach już działać nie chce.
  1. <http://december.com/html/4/element/input.html id="code-346e29251" type="text" class="form-control form-control-user" value="346e2925162e85954886a9021f32da7b" readonly="">
  2. <http://december.com/html/4/element/a.html href="#" onclick="CopyToClipboard('code-346e29251);return false;"><http://december.com/html/4/element/i.html class="fas fa-copy"></http://december.com/html/4/element/i.html></http://december.com/html/4/element/a.html>
Ktoś wytłumaczy dlaczego?

Napisany przez: trueblue 5.07.2022, 08:06:14

Google Twoim przyjacielem: https://stackoverflow.com/a/5072684

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)