Skip to content

Commit

Permalink
[ JS ] SMS
Browse files Browse the repository at this point in the history
  • Loading branch information
eunbeann committed May 19, 2024
1 parent 51ce7a3 commit 6957043
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions JS/window.location.href=sms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
```jsx
window.location.href = sms:?body=${encodeURIComponent("hi")};

```
**`window.location.href`**
- 현재 웹사이트의 URL 변경
**`sms:?body=${encodeURIComponent("hi")}`**
- SMS URL 구성
- sms:
- URL 스키마
- body:
- 메시지 본문 지정 매개 변수
**`encodeURIComponent("hi")`**
- 메시지 본문의 텍스트 “hi” 인코딩
- 예시엔 특수문자가 없기 때문에 sms?body=hi와 같이 평가되지만 실제 사용에서는 그렇지 않기 떄문에 **`encodeURIComponent` 필요**
### 실제 사용 예시
[[ FEAT ] 문자메시지로 공유하기 기능 추가 ](https://github.com/Gwasuwon-shot/Tutice_Client/pull/470)
```jsx
function handleShareViaMessage() {
const message = `안녕하세요, 과외 수업 관리 필수 앱 Tutice 입니다. \n\n[${userName}]선생님이 [${studentName}]학생의\nTutice 초대장을 보냈습니다.\n\nTutice 링크 \n ${URL}`;
const smsLink = `sms:?body=${encodeURIComponent(message)}`;
window.location.href = smsLink;
}
```

0 comments on commit 6957043

Please sign in to comment.