-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_application.html
74 lines (66 loc) · 2.24 KB
/
my_application.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<h2>Trail for placements</h2>
<p id="token"></p>
<script src="https://www.gstatic.com/firebasejs/7.14.6/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.6/firebase-messaging.js"></script>
<script>
var firebaseConfig = {
apiKey: "AIzaSyBkgKr-g2T-tqeDGKw6VrP8kbmcza1gXVs",
authDomain: "placements-91014.firebaseapp.com",
projectId: "placements-91014",
storageBucket: "placements-91014.appspot.com",
messagingSenderId: "112599018232",
appId: "1:112599018232:web:6011e23bbe7b34f1c1290d",
measurementId: "G-645Q45R2RC"
};
firebase.initializeApp(firebaseConfig);
const messaging=firebase.messaging();
function IntitalizeFireBaseMessaging() {
messaging
.requestPermission()
.then(function () {
console.log("Notification Permission");
return messaging.getToken();
})
.then(function (token) {
console.log("Token : "+token);
document.getElementById("token").innerHTML=token;
})
.catch(function (reason) {
console.log(reason);
});
}
messaging.onMessage(function (payload) {
console.log(payload);
const notificationOption={
body:payload.notification.body,
icon:payload.notification.icon
};
if(Notification.permission==="granted"){
var notification=new Notification(payload.notification.title,notificationOption);
notification.onclick=function (ev) {
ev.preventDefault();
window.open(payload.notification.click_action,'_blank');
notification.close();
}
}
});
messaging.onTokenRefresh(function () {
messaging.getToken()
.then(function (newtoken) {
console.log("New Token : "+ newtoken);
})
.catch(function (reason) {
console.log(reason);
//alert(reason);
})
})
IntitalizeFireBaseMessaging();
</script>
</body>
</html>