riberio
[javascript] 클립보드로 URL 복사하기 본문
< div id="layerCopyShareUrl" style="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;padding:0;border:0;">< /div>
$("#layerCopyShareUrl").html("");
$("#layerCopyShareUrl").html(window.location.href);
let clip = document.getElementById("layerCopyShareUrl");
if(document.body.createTextRange) {
let range = document.body.createTextRange();
range.moveToElementText(clip);
range.select();
document.execCommand("Copy");
alert("Copied1");
document.selection.empty();
}
else if(window.getSelection) {
let selection = window.getSelection();
let range = document.createRange();
range.selectNodeContents(clip);
selection.removeAllRanges();
selection.addRange(range);
document.execCommand("Copy");
alert("Copied2");
selection.removeAllRanges();
}
'개발 관련 > JAVASCRIPT' 카테고리의 다른 글
모바일 첨부 이미지 미리보기 (0) | 2020.06.11 |
---|---|
두지점의 위도,경도 기준 최단거리 계산 (0) | 2019.11.12 |
현재 위치 기반 위도경도 조회 (0) | 2019.11.07 |
javascript 배열, key-value 사용 (0) | 2019.10.07 |
javascript 날짜 비교 함수 (0) | 2017.04.11 |