你好
我已经核对了PushPad:在站点刷新后删除订阅问题的答案,但这对我没有帮助。
我在文档之后创建了一个订阅/取消订阅按钮,每次我点击订阅按钮时,提示都会出现在火狐上,所以我想我的流程是正确的,但我不明白为什么它不能在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
});
}
});谢谢你帮我弄清楚。
发布于 2018-11-07 13:35:40
$(function () { ... }中,以便在页面完全加载时运行代码,否则单击处理程序可能无法正常工作。https://stackoverflow.com/questions/53189110
复制相似问题