버튼 클릭시 현재 url을 복사하고싶습니다..

버튼 클릭시 현재 url을 복사하고싶습니다..

QA

버튼 클릭시 현재 url을 복사하고싶습니다..

답변 4

본문


<?
$url  = $_SERVER['SERVER_NAME'].'/'.$_SERVER['PHP_SELF'];
?>
<button onclick="copy_to_clipboard()">Select</button>
<br/>
<input type="text" id="myInput" value="<?php echo $url; ?>">
<script>
function copy_to_clipboard() {
  $("#myInput").select();
  document.execCommand("copy");
  alert('복사되었습니다.');
}
</script>

 

이런식으로 현재 url을 input에 넣어서 복사하는데 까지는 성공했습니다!

그런데 저는 input이 필요없어서 보여주기싫어서...

display:none;을 하니

복사가 되지않고...

그냥 단순하게 버튼을 클릭하면

현재 url을 복사하고싶습니다.

조언좀 부탁드립니다.ㅠㅠ

이 질문에 댓글 쓰기 :

답변 4

<input type="text" id="myInput" value="<?php echo $url; ?>">

대신

<input type="button"  id="myInput" value="url 복사 ">

 

스크립트를

$("#myInput").attribute("value","<?php echo $url; ?>")

$("#myInput").select();

document.execCommand("copy");

$("#myInput").attribute("value","url 복사")

이런식으로 하면 안될까요?

input type="text" 대신에 input type="hidden" 을 사용하시면 되지 않나요?

input type을 text 말고 hidden 으로 해보세요

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 10,633
© SIRSOFT
현재 페이지 제일 처음으로