javascriptjquerydotnetnukedotnetnuke-module

DotNetNuke include javascript on every page


I want to create a module that basically includes javascript on to every page on a dotnetnuke site. I can include a js file in the current page,

ClientResourceManager.RegisterScript(this.Page, 
"~/DesktopModules/AuthenticationServices/ZapperScanToLogin/view.js", 
FileOrder.Js.jQuery); 

but what I really want to do is install my module on the home page and it will include javascript on to every page on the dnn site. Is this possible, how can I do it?


Solution

  • What I ended up doing was including a javascript registration in the js/debug/dnn.modalpopup.js file, which then registers my javascript on the login and registration pages and popup dialogue boxes.

            var myView = document.createElement("script");
            myView.type = "text/javascript";
            myView.src = "/js/view.js";
    
            var myTech = document.createElement("script");
            myTech.type = "text/javascript";
            myTech.src = "/js/mytech.js";
    
    
            document.head.appendChild(myView);
            document.head.appendChild(myTech);
    

    I am not sure placing the javascript files in that location is ideal or not, but this is the solution that works for me. I think the manual dev work per DNN site will be minimal so I hope it's an acceptable solution.

    I am not sure whether I should put the script in the page head, or the body... the order of loading and what not of javascript is a mystery to me.