Search code examples
dotnetnuke

DNN how to inject JavaScript code in all pages in between <head> tags


I am trying to insert a piece of JavaScript code in all my pages at once if that's possible. I'm hoping this is possible but I've yet to encounter how to do it. The code needs to go in between the tags.


Solution

  • In DNN9 (perhaps earlier versions) on the Site Settings page there's a HTML Page Header Tags setting in which you can add whatever you like.

    enter image description here

    You could also do it through code, in your SKIN, or by creating a Module that you put on every page.

    RegisterScript(Page page, string filePath, FileOrder.Js priority) // default provider, uses fileorder enumeration
    

    Documentation is at

    http://www.dnnsoftware.com/wiki/client-resource-management-api

    When all else fails, add it to the default.aspx file, but if you do that, know that when you upgrade DNN, you'll lose those changes.