Forum Discussion

rsinayev's avatar
rsinayev
Contributor
10 years ago

Adding Javascript to a page HEAD

We’re trying to add some custom javascript to all of the pages on our Lithium site.  We’ve built a custom component, added the code, and added the compontent to the appropriate pages.  The problem is that for all the locations we can add it to, it will end up embedded deep within a DIV structure.  Due to modern browser XSS prevention techniques, such scripts just get ignored by the browser.  So Is there a way to add javascript, either with a component, or with some other means, that will end up in the “HEAD” of the document, or at the very least, the root level of the BODY.
Has anyone else found a reliable way to embed static trusted javascript on one or more pages?

  • Hey

    If you need to add to all pages, have you looked at adding to the head or hitbox within the skin wrapper from studio? You could dump the code in there and it should display on every page.

2 Replies

  • Hey

    If you need to add to all pages, have you looked at adding to the head or hitbox within the skin wrapper from studio? You could dump the code in there and it should display on every page.
  • nathan's avatar
    nathan
    Executive
    10 years ago

    Just to add to Stephen's comment, if you want to restrict the JavaScript to only appear on certain pages, you've got a couple of options:

    1. Use some FreeMarker in the head component.
    2. Create a second skin with the JavaScript in the wrapper head, and apply this to the appropriate pages (probably a bit OTT)