Receive our newsletter – data, insights and analysis delivered to you
  1. Uncategorised
March 25, 2020

Unsubscribe from push notifications

By Chris Boyle

function updateMangeWebPushSubscriptionButton(buttonSelector) { var hideWhenSubscribed = false; var subscribeText = "Subscribe to Notifications"; var unsubscribeText = "Unsubscribe from Notifications";

getSubscriptionState().then(function(state) { var buttonText = !state.isPushEnabled || state.isOptedOut ? subscribeText : unsubscribeText;

var element = document.querySelector(buttonSelector); if (element === null) { return; }

element.removeEventListener('click', onManageWebPushSubscriptionButtonClicked); element.addEventListener('click', onManageWebPushSubscriptionButtonClicked); element.textContent = buttonText;

if (state.hideWhenSubscribed && state.isPushEnabled) { = "none"; } else { = ""; } }); }

Content from our partners
Extractables and leachables analysis in pharmaceutical quality control
How Hengst helped to keep Germany’s charity “star singers” shining
Why this global life sciences COO believes relocation to Charleston, SC, was key to achieving next-level success

function getSubscriptionState() { return Promise.all([ OneSignal.isPushNotificationsEnabled(), OneSignal.isOptedOut() ]).then(function(result) { var isPushEnabled = result[0]; var isOptedOut = result[1];

return { isPushEnabled: isPushEnabled, isOptedOut: isOptedOut }; }); }

var OneSignal = OneSignal || []; var buttonSelector = "#my-notification-button";

/* This example assumes you've already initialized OneSignal */ OneSignal.push(function() { // If we're on an unsupported browser, do nothing if (!OneSignal.isPushNotificationsSupported()) { return; } updateMangeWebPushSubscriptionButton(buttonSelector); OneSignal.on("subscriptionChange", function(isSubscribed) { /* If the user's subscription state changes during the page's session, update the button text */ updateMangeWebPushSubscriptionButton(buttonSelector); }); });

Related Companies

NEWSLETTER Sign up Tick the boxes of the newsletters you would like to receive. A weekly roundup of the latest news and analysis, sent every Friday. The pharmaceutical industry's most comprehensive news and information delivered every month.
I consent to GlobalData UK Limited collecting my details provided via this form in accordance with the Privacy Policy