반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- VirtualBox
- react
- androidstudio
- jest
- xcode
- 개발
- node
- 맥
- 티스토리챌린지
- TensorFlow
- MachineLearning
- vsCode
- IOS
- centos
- Chrome
- 오블완
- ReactNative
- linux
- MAC
- unittest
- localserver
- PYTHON
- webpack
- Android
- 네트워크
- 센토스
- build
- qunit
- 리눅스
Archives
- Today
- Total
로메오의 블로그
[javascript] Web Notification API 본문
반응형
웹브라우저에서 알림창을 표시하는 HTML5 Web Notification API 입니다.
<a href="#" id="requestPermission">권한요청</a>
<a href="#" id="showNotification">알림표시</a>
var requestPermission = document.querySelector('#requestPermission')
var showNotification = document.querySelector('#showNotification')
// 알림 권한 요청
requestPermission.addEventListener('click', () => {
if (!window.Notification) {
alert('지원하지 않음')
} else {
Notification.requestPermission().then(p => {
if (p == 'denied') {
alert('알림을 허용하지 않았습니다.')
} else if (p == 'granted') {
alert('알림을 허용했습니다.')
}
})
}
})
// 알림 표시
showNotification.addEventListener('click', () => {
if (Notification.permission!=='default') {
let notify = new Notification('알림이 왔습니다.', {
'body': '안녕하세요. \n알림을 성공적으로 수신했습니다.',
'icon': 'https://tistory3.daumcdn.net/tistory/2979840/attach/6e5d2d16ab6a49628dfe1f4c164e38a0',
'tag': '메시지'
})
notify.onclick = function(){
alert(this.tag)
}
} else {
alert('알림을 허용해 주세요.')
}
})
https://codepen.io/romeoh/pen/jOOZWdw
디버그 모드:
https://cdpn.io/romeoh/debug/jOOZWdw/nqAwvWGzXaqr
반응형
'Frontend > ETC' 카테고리의 다른 글
[엑셀] 새로운 창으로 엑셀 파일 열기 - 엑셀 창 분리 (1) | 2020.03.11 |
---|---|
[VSCode] VS Code Terminal에서 스크립트 실행이 안됨 - Windows (1) | 2020.01.07 |
[Chrome] IndexedDB 사용하기 (1) | 2019.09.19 |
[Chrome] Web SQL 사용하기 (1) | 2019.09.13 |
[Buy Me a Coffee] tistory에 Buy Me a Coffee 배너 달기 (1) | 2019.08.26 |
Comments