HTML JS 뒤로가기, 공유하기 버튼 만들기

hyunjung Koo·2021년 9월 19일
0

두 가지 이상의 .HTML 파일을 넘나들 때, 웹 페이지를 공유할 때

  • [뒤로가기] 버튼에 JS 사용하여 코드 작성하기.
  • [공유하기] 버튼에 JS 사용하여 코드 작성하기.

Javascript [뒤로가기] head에 작성해 줍니다.

 <script>
       function back(){
       let url = window.location.href;
       let new_url = url.split('result.html')[0] + 'index.html';
        window.location.href= new_url;
        }
</script>

Javascript [공유하기] head에 작성해 줍니다.

   <script>
   function share(){
        var t = document.createElement("textarea");
            document.body.appendChild(t);
            t.value = window.location.href;
            t.select();
            document.execCommand('copy');
            document.body.removeChild(t);
            alert('복사 완료!')
        }
  </script>

끝 :)

profile
날마다 꾸준히 성장하는 Software Engineer

0개의 댓글