[JavaScript] 클립보드 복사

// $textarea
const myTextarea = document.querySelector(".view");
// button 클릭 이벤트
document.querySelector("#btn_copy").onclick = () => {
    // textarea의 내용을 복사한다.
    var replace_txt = myTextarea.innerText.replace(/(사주운세홈 바로가기|나의 운세 복사하기|사주풀이 보러가기)/gi,"");
    window.navigator.clipboard.writeText(replace_txt).then(() => {
        // 복사가 완료되면 호출된다.
        alert("복사되었습니다. 메모장에 붙여넣고 저장하여 사용하시기 바랍니다.");
    });
};

아이프레임 내용 복사시 퍼미션 에러나면 속성에

allow=”clipboard-read; clipboard-write”

추가

<iframe id="unseggun_ifr" src="https://www.unseggun.com/herald/test.php" scrolling ="no" frameborder="0" width="100%" height="1000" marginwidth="0" marginheight="0" allow="clipboard-read; clipboard-write"></iframe>

guest
0 Comments
Inline Feedbacks
View all comments