• Resolved Adriano Monecchi

    (@designroom)


    The following code shows how to Trigger Custom Link Permission Message.

    https://documentation.onesignal.com/docs/customize-permission-messages

    I’d like to allow the user to subscribe/unsubscribe by clicking on a checkbox toggle. Is there a way to make this happen by passing additional parameters to OneSignal while checking for the checkbox toggle value?

    <body>
        <a href="#" id="subscribe-link" style="display: none;">Subscribe to Notifications</a>
        <script>
            function subscribe() {
                OneSignal.push(["registerForPushNotifications"]);
                event.preventDefault();
            }
    
            var OneSignal = OneSignal || [];
            /* This example assumes you've already initialized OneSignal */
            OneSignal.push(function() {
                // If we're on an unsupported browser, do nothing
                if (!OneSignal.isPushNotificationsSupported()) {
                    return;
                }
                OneSignal.isPushNotificationsEnabled(function(isEnabled) {
                    if (isEnabled) {
                        // The user is subscribed to notifications
                        // Don't show anything
                    } else {
                        document.getElementById("subscribe-link").addEventListener('click', subscribe);
                        document.getElementById("subscribe-link").style.display = '';
                    }
                });
            });
        </script>
    </body>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom function for notification checkbox toggle’ is closed to new replies.