Is there a way in a single web-push-sdk signal to manually add a user and unsubscribe?
I tried this in my function subscribeOneSignal(), but nothing happened.
OneSignal.push(function() {
OneSignal.registerForPushNotifications();
});
I have a simple html page where I have two buttons: one is "Subscribe" and the other is "Unsubscribe", now when the user clicks the "Subscribe" button, he should add one signal, and when he clicked the " Unsubscribe, "he should not receive notifications.
<!DOCTYPE html>
<html>
<head>
<link rel="manifest" href="/manifest.json">
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
<script>
var OneSignal = window.OneSignal || [];
OneSignal.push(["init", {
appId: "345345-asdf-345",
autoRegister: false,
notifyButton: {
enable: true
}
}]);
function subscribeOneSignal(){
OneSignal.push(function() {
OneSignal.registerForPushNotifications();
});
OneSignal.push(function() {
OneSignal.registerForPushNotifications({
modalPrompt: true
});
});
}
function unSubscribeOneSignal(){
}
</script>
</head>
<body>
<p>OneSingle Testing</p>
<br>
<button onclick="subscribeOneSignal()">Subscribe </button>
<button onclick="unSubscribeOneSignal()">Unsubscribe </button>
</body>
</html>
source
share