-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiframe.html
36 lines (34 loc) · 1.35 KB
/
iframe.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
<!DOCTYPE html>
<html lang="en">
<html>
<body>
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
<script>
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "1db1662c-7609-4a90-b0ad-15b45407d628",
});
});
// Make sure OneSignal Init code is on this page
function bindEvent(element, eventName, eventHandler) {
element.addEventListener(eventName, eventHandler, false);
}
// Accessed within iframe on subdomain.site
// Sends a message to mainsite
var sendMessage = function (msg) {
console.log(`2 Mainsite is Sending Message to subdomain.site ${msg}`)
// postMessage: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
window.parent.postMessage(msg, 'https://onesignaldemo.github.io');
};
bindEvent(window, 'load', function (e) {
OneSignal.push(function() {
OneSignal.isPushNotificationsEnabled(function(isEnabled) {
console.log(`1 subdomain.site iframe checking subscription from mainsite, it is ${isEnabled}`)
sendMessage(isEnabled)
});
});
});
</script>
</body>
</html>