0

다음의 Coffescript 코드를 실행하여 특정 데이터를 사용자 클립 보드에 복사합니다. 연속 선택이 지원되지 않습니다. 오류 중지 클립 보드로 복사

ready = -> 

copyEmailBtn = document.querySelector('.clipboard-copy') 
copyEmailBtn.addEventListener 'click', (event) -> 
    targetClass = document.querySelector('.clipboard-copy').dataset.targetClass 
    target = document.querySelector(targetClass) 
    range = document.createRange() 
    range.selectNode target 
    window.getSelection().addRange range 
    try 
    document.execCommand('copy') 
    catch err 
    console.log 'Oops, unable to copy' 
    window.getSelection().removeAllRanges() 
    return 

if $('.clipboard-copy').length > 0 
    $(document).ready(ready) 
    $(document).on('page:load', ready) 

When I click the related button to start the copy process chrome throws the following error

이 가진 문제

나는 단지 4 개 시도 중 하나에서 발생하기 때문에 그것을 추적 할 수없는 생각이다.

복사 버튼이 다른 3 번 4 번과 같이 예상대로 작동하지만이 오류가 발생할 때마다 텍스트를 복사하지 않습니다.

우리의 앱이 다른 브라우저에서 작동하지 않아서 작동하지 않기 때문에 다른 브라우저를 사용하지 않았습니다.

이전에이 오류를 겪은 사람이 있습니까? 이 오류에 대한 다른 모든 보고서는이 기능에 영향을하고 더 자세한 경고처럼 안 말할 코드 Discontiguous selection is not supported

에서 볼 수

나는 다음과 같은 제안을 시도했다.

답변

0

는 다음 코드

ready = -> 

copyEmailBtn = document.querySelector('.clipboard-copy') 
copyEmailBtn.addEventListener 'click', (event) -> 
    window.getSelection().removeAllRanges() 
    targetClass = document.querySelector('.clipboard-copy').dataset.targetClass 
    target = document.querySelector(targetClass) 
    range = document.createRange() 
    range.selectNode target 
    window.getSelection().addRange range 
    try 
    document.execCommand('copy') 
    catch err 
    console.log 'Oops, unable to copy' 
    window.getSelection().removeAllRanges() 
    return 

if $('.clipboard-copy').length > 0 
    $(document).ready(ready) 
    $(document).on('page:load', ready) 
으로 고정