Redirectionare dupa acceptare notificari prin OneSignal

Discutii si intrebari legate de scripturi si functii JavaScript, jQuery si Ajax, cod JavaScript in general.
mluci
Mesaje: 29

Redirectionare dupa acceptare notificari prin OneSignal

Buna ziua, am site-ul today-news.eu
As vrea ca dupa ce utilizatorul accepta notificarile primite prin Onesignal sa il redirectionez spre o pagina de bun venit.
Aveti idee cum pot face asta?

MarPlo
Salut,
Vezi ce afiseaza in consola la clic pe Allow /Accept.
In documentatia de la:
documentation.onesignal.com/docs/web-push-sdk#section-notification-permission-change
spune asa pentru valoarea returnata de: permissionChange.to

Cod: Selectaţi tot

If to is "granted", the user has allowed notifications.
If to is "denied", the user has blocked notifications.
If to is "default", the user has clicked the 'X' button to dismiss the prompt.
- Deci, in codul tau verifici acea valoare si faci redirect cu window.location.
Incearca asa:

Cod: Selectaţi tot

OneSignal.on('notificationPermissionChange', function(permissionChange){
  var currentPermission = permissionChange.to;
  if(currentPermission =='granted'){
    window.location.href ='https://marplo.net'; //pagina pt. redirect
    return;
  }
  console.log('New permission state:', currentPermission);
});

Subiecte similare