2994
Views
9
Comments
Adding Script Code to HTML Header
Question

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>
2025-04-23 09-24-58
oDevFagundes
Champion

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;
});


UserImage.jpg
Bil Mizan

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

2023-02-10 19-42-59
João Melo
 
MVP

Well, it is possible:

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

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

2023-12-07 07-51-40
Remco Dekkinga
 
MVP

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.

UserImage.jpg
Peter Laurion

Where would I put the AddJavaScriptTag function in order to include it on a page? I've tried in the OnInitialize function, but it doesn't work there.

Thanks,

2024-03-25 06-19-08
Harlin Setiadarma

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?

Harlin OneSignal Plugin.oap
2021-06-09 13-39-18
Agno Silveira
 
MVP

Hello guys,

I have a similar problem, i need to add a specific script on <head>, 

<script type="text/javascript">
        dataLayer = [{
            'TyperUser': '" + UserType + "',
            'Screen': '" + PageName + "'
        }];
</script>

but, without src=.

How i need get the page name, i'm trying doing at OnBeginWebRequest, to create a script in my all pages.



I need the result in the html <head> to be the same as:


if someone could help me, i would be very grateful.

Tnks.


2021-06-09 13-39-18
Agno Silveira
 
MVP

Agno Silveira wrote:

Hello guys,

I have a similar problem, i need to add a specific script on <head>, 

<script type="text/javascript">
        dataLayer = [{
            'TyperUser': '" + UserType + "',
            'Screen': '" + PageName + "'
        }];
</script>

but, without src=.

How i need get the page name, i'm trying doing at OnBeginWebRequest, to create a script in my all pages.



I need the result in the html <head> to be the same as:


if someone could help me, i would be very grateful.

Tnks.


Solution, for this case:

https://www.outsystems.com/forums/discussion/60447/add-script-in-all-pages-without-src/


2024-06-19 07-19-32
JitendraYadav

Hi,


could be helpful,


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.