This sample code shows how to add push notifications to your website using OneSignal and JavaScript.
Learn how to get the OneSignal App ID and OneSignal API Key here.
You can add the following code to your index.js file like shown in this code sample or inside of you html <head>
tag wrapped with a <script>
tag.
The following code will make OneSignal aware that this website will be using the OneSignal Push Notifications and it will allow the users to subscribe to the website to start receving the notifications.
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "YOUR-APP-ID",
safari_web_id: "YOUR-SAFARI-WEB-ID",
notifyButton: {
enable: true,
size: "small",
position: "bottom-left",
},
allowLocalhostAsSecureOrigin: true,
});
});
In the code above, We are using the notifyButton property which will add a bell Icon with the properties specified such as the size and the position.
Give a ⭐️ if this project helped you!
The OneSignal Developer community is a group of passionate individuals who work with OneSignal products. Community members have the opportunity to expand their network and knowledge across different technologies.
- Website: https://onesignal.com/onesignal-developers
- Twitter: @OneSignalDevs
- Github: @OneSignalDevelopers
- Discord: @onesignal-metabase