你好,
我已经检查了PushPad: Subscribe is removed after site refresh问题的答案,但这对我没有帮助。
我按照文档创建了一个订阅/取消订阅按钮,每次单击订阅按钮时都会在 Firefox 上显示提示,所以我想我的流程是正确的,但我不明白为什么它在 Chrome 上不起作用 =>提示仅在我第一次启动 Chrome 时显示。
这就是我所做的
pushpad('init', #projectID);
var pushId = $("#main").data("pushid");
var pushSig = $("#main").data("pushsig");
var updateButton = function (isSubscribed) {
var btn = $('#activate-push-notif');
if (isSubscribed) {
btn.html('Unsubscribe');
btn.addClass('subscribed');
} else {
btn.html('Subscribe');
btn.removeClass('subscribed');
}
};
// check whether the user is subscribed to the push notifications and
// initialize the button status (e.g. display Subscribe or Unsubscribe)
pushpad('status', updateButton);
// when the user clicks the button...
$('#activate-push-notif').on('click', function (e) {
e.preventDefault();
// if he wants to unsubscribe
if ($(this).hasClass('subscribed')) {
pushpad('unsubscribe', function () {
updateButton(false);
}, {
uid: pushId,
});
// if he wants to subscribe
} else {
// try to subscribe the user to push notifications
pushpad('subscribe', function (isSubscribed) {
if (isSubscribed) {
updateButton(true);
} else {
updateButton(false);
alert('You have blocked notifications from your browser preferences.');
}
}, {
uid: pushId,
uidSignature: pushSig
});
}
});
感谢您帮助解决这个问题。