Setup delay to show slidedown permission message
-
Hello!
I’m tryin to setup delay to prompt permission message after X visits only.
But i want to show slidedown permission message with my text and nice buttons yes/now (showHttpPrompt), and if user clicks “Yes” – to show him deafult HTTPS promt which calls by
registerForPushNotifications();
But i can’t correctly modify script from this documentation.
If i’m changing
window.OneSignal.registerForPushNotifications();
to
window.OneSignal.showHttpPrompt();
(like in this ticket) – i see this slidedown window, but if i click “yes” – nothing happens.I’ve tried to take code from plugin source code and changed:
window.OneSignal.registerForPushNotifications();
to:window.OneSignal.showHttpPrompt(); window.OneSignal.init(window._oneSignalInitOptions);
It works, if i click yes in slidedown permission than i see classic permission request near to the SSL symbol. But in console i see massage about
SdkInitError {reason: "MultipleInitialization", message: "OneSignal: The OneSignal web SDK can only be initi…remove calls initializing the SDK more than once.", name: "SdkInitError", stack: "SdkInitError: OneSignal: The OneSignal web SDK can…/cdn.onesignal.com/sdks/OneSignalSDK.js:1:147251)"} reason: "MultipleInitialization" message: "OneSignal: The OneSignal web SDK can only be initialized once. Extra initializations are ignored. Please remove calls initializing the SDK more than once."
How to correctly modify this script?
<!-- data-cfasync: Ignore CloudFlare's Rocket Loader, which may impact the triggering of the DOMContentLoaded event (see: https://goo.gl/CvZewv) --> <script data-cfasync="false"> window.OneSignal = window.OneSignal || []; var numVisitsTrigger = 3; /* Number of page visits before prompting user */ /* Why use .push? See: https://stackoverflow.com/a/38466780/555547 */ window.OneSignal.push(function() { var numVisits = new Number(localStorage['numVisitsTrigger'] || 0); numVisits += 1; localStorage['numVisitsTrigger'] = numVisits; if (numVisits >= numVisitsTrigger) { promptAndSubscribeUser(); } }); function promptAndSubscribeUser() { /* Want to trigger different permission messages? See: https://documentation.onesignal.com/docs/permission-requests#section-onesignal-permission-messages */ window.OneSignal.isPushNotificationsEnabled(function(isEnabled) { if (!isEnabled) { window.OneSignal.registerForPushNotifications(); } }); } </script>
- The topic ‘Setup delay to show slidedown permission message’ is closed to new replies.