Adding Script Code to HTML Header

Adding Script Code to HTML Header

  

Hi,

I'm looking for the best way i can include the following HTML code to the Header tags for Web App.

It's the coed for Web push notifications from OneSignal.com

<head>
  <link rel="manifest" href="/manifest.json">
  <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
  <script>
    var OneSignal = window.OneSignal || [];
    OneSignal.push(["init", {
      appId: "YOUR_APP_ID",
      autoRegister: false,
      notifyButton: {
        enable: true /* Set to false to hide */
      }
    }]);
  </script>
</head>

Hi Bil Mizan, I'm not sure if it's possible.

Why don't you use Jquery.ready? Try to put code javascript on body of HTML and using the Jquery.ready.

$( document ).ready(function() {  
    your code;
});


Well, it is possible:

$('head').append('<script>...');

But it's mor like an work around. I like @Paulo's solution more... ;)

Paulo Ricardo Fagundes Junior wrote:

Hi Bil Mizan, I'm not sure if it's possible.

Why don't you use Jquery.ready? Try to put code javascript on body of HTML and using the Jquery.ready.

$( document ).ready(function() {  
    your code;
});



Hi paolo, Could you help me step by step how to add it as am totally new to JS

Adding javascript is always possible, but I would vote for an OutSystems way of adding the link and script tags. 

Add the dependencies for "AddJavaScriptTag" and "AddLinkTag" from them HTTPRequestHandler extension.

Bil Mizan wrote:

Hi,

I'm looking for the best way i can include the following HTML code to the Header tags for Web App.

It's the coed for Web push notifications from OneSignal.com

<head>
  <link rel="manifest" href="/manifest.json">
  <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
  <script>
    var OneSignal = window.OneSignal || [];
    OneSignal.push(["init", {
      appId: "YOUR_APP_ID",
      autoRegister: false,
      notifyButton: {
        enable: true /* Set to false to hide */
      }
    }]);
  </script>
</head>

Hi, there is a plugin for OneSignal already on Forge.

And I also have customized it, so you can send notification to specific user easily.

You can also tag user with specific key-value pair, example: segment=areamanager, then send notification to that specific tag.

I attached my customized OneSignal Plugin on this post, so maybe you can jumpstart using it already...


Steps:

1. Put OneSignal block on your Common\Layout (directly under root element)

2. Call RegisterDevice in your On-Logon (after DoLogin/UserLogin)

3. Use PostNotificationToUser action to send push notification


EDIT: Ooops sorry, I didn't read the Web Push part... Maybe it uses same API?