To trigger the browser's native permission prompt from your own custom HTML element (like a button or a link), you must use the Pushwoosh.subscribe() JavaScript API method.
If your custom button is not working and you see an Error: Unknown command! in your browser's developer console, you are likely using an incorrect method to call the subscription. For example, Pushwoosh.push(['subscribe']) is not the correct way to trigger the prompt.
Correct Implementation
- Ensure the Pushwoosh Web SDK is initialized on your page.
- Add an event listener to your custom button that calls
Pushwoosh.subscribe().
Here is an example using a button with the ID custom-subscribe-button:
<button id="custom-subscribe-button">Subscribe Now</button>
document.getElementById("custom-subscribe-button").addEventListener("click", function () {
try {
if (typeof Pushwoosh !== "undefined") {
// This is the correct function to call
Pushwoosh.subscribe();
}
} catch (e) {
console.error("Pushwoosh subscribe error:", e);
}
});
When this function is called, Pushwoosh will show the native browser permission prompt to the user.
Comments
0 comments
Please sign in to leave a comment.