Skip to content

OneSignalDevelopers/OneSignal-PushNotification-JavaScript-Sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OneSignal-PushNotification-JavaScript-Sample

Maintenance Twitter: onesignaldevelopers

This sample code shows how to add push notifications to your website using OneSignal and JavaScript.

Requirements

OneSignal Keys

Learn how to get the OneSignal App ID and OneSignal API Key here.

Adding OneSignal To Your Website

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.

Show Your Support

Give a ⭐️ if this project helped you!

Join the OneSignal Developers Community

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published