programing

로컬에서 작동하지만 서버에서는 작동하지 않는 클립보드 기능 복사

javajsp 2023. 8. 17. 20:47

로컬에서 작동하지만 서버에서는 작동하지 않는 클립보드 기능 복사

다음 스크립트를 사용하고 있습니다.그것은 비주얼 스튜디오에서 로컬로 작동하고 있습니다.하지만 서버에서 그것은 던집니다.

"정의되지 않은 '텍스트 쓰기' 속성을 읽을 수 없습니다."

 function GetCopyText(thislink) {
    var Content = thislink.parentNode.parentNode.parentNode.parentElement.parentElement.parentElement.parentElement.children[2].children[0].children[0].innerText;

    navigator.clipboard.writeText(Content).then(function () {
        // alert('Async: Copying to clipboard was successful!');
    }, function (err) {
        console.error('Async: Could not copy text: ', err);
    });
}

프로토콜 https를 만들면 브라우저에서 실행해야 합니다.

클립보드 기능은 일부 또는 모든 지원 브라우저에서 보안 컨텍스트(HTTPS)에서만 사용할 수 있습니다.

https://developer.mozilla.org/en-US/docs/Web/API/Clipboard

고마워 웨이드

제안: navigator.clipboard 값을 확인하고 있는 경우에만 진행하는 것이 좋습니다.이것은 좋은 사용자 경험을 제공하며 대규모 조직에서는 많은 개발자들이 테스트를 위해 로컬 모드에서 UI를 실행할 것이기 때문에 디버깅 시간을 절약하고 나서 navigator.clipboard가 https 없이 로컬 모드에서 사용할 수 없다는 것을 알게 됩니다.

언급URL : https://stackoverflow.com/questions/52054635/copy-clipboard-function-working-locally-but-not-working-server