Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

82 lines (75 sloc) 3.19 KB
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<script src="javascripts/onesignal-init.js"></script>
<script src="" async="async"></script>
function log() {
var args =;
args.unshift(location.href + ':');
console.log.apply(console, args);
log('iFrame page loaded and script running.');
/* From: */
var OneSignal = window.OneSignal || [];
// Called sometime after postMessage is called
function receiveMessage(event) {
log('Received a postMessage message:', event);
// Do we trust the sender of this message?
// TODO: Be sure to implement this in the future!
// if (event.origin !== "" || // event.origin !== "" || // event.origin !== "") // return;
// event.source is window.opener
// is {command: 'query', extra: {}}
// Assuming you've verified the origin of the received message (which
// you must do in any case), a convenient idiom for replying to a
// message is to call postMessage on event.source and provide
// event.origin as the targetOrigin.
if ( === 'query') {
OneSignal.push(function () {
]).then(function (results) {
log('Got subscription state, tags, and user ID from iFrame:', results);
command: 'reply',
extra: results
.catch(function (e) {
log('Error in retrieving iframe state:', e);
} else if ( === 'subscribe') {
log("Setting a tag on this user record to mark that he's subscribing on:" ,;
OneSignal.push(function() {
var tags = {};
tags[] = true;
The user is already subscribed to push notifications on
All sites opening a popup to share a subscription.
To simulate separate subscriptions for sites, we'll just tag the subscriber as
having subscribed on multiple sites using our tagging system (key-value attribute pairs)
and when we send notifications we can target users with only a specific site's tag.
The tag key is the site's origin. e.g.
window.addEventListener("message", receiveMessage, false);
OneSignal.push(function() {
OneSignal.on('initialize', function() {
window.addEventListener("message", receiveMessage, false);
You can’t perform that action at this time.