Question

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?

Was it helpful?

Solution 5

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.

OTHER TIPS

I would honestly do this with a modification to your skin, but here are the steps to do it with a module.

  1. Create a module (I recommend starting with my templates http://christoctemplate.codeplex.com)
  2. Add your JS code
  3. Add the module to the homepage
  4. Go to the module settings, choose Display on All Pages

I would add this to your skin, either just manually by adding the reference, or by creating a SkinObject rather than a module.

If you do it as a module it is possible that a user can delete the module from the page, or a number of other things. if this script is a requirement it is best to make it so that users can't break the site by doing something accidentally.

One way to do it is add to the header of the site, under site settings. Logged in as SuperUser:

  1. Go Settings (Cog) Site Settings
  2. Site behavior Tab - Default Pages
  3. At the bottom: Page Output Settings
  4. HTML Page Header Tags: add your script link:

Sample below. Does not show up at bottom of page, shows up top in header, but will be on every page.

<script type="text/javascript" src="/Portals/0/Your-js-here.js"></script> 

There ought to be a page template for your module which you can edit and insert the jQuery script reference into the header of (in between the <head> tags). This would then be loaded on each page of the module.

Here are a couple of references that might help: http://wnsinj.codeplex.com/ http://www.dnnsoftware.com/community-blog/cid/135141/DotNetNuke-Tips-and-Tricks-11-Using-jQuery-in-DotNetNuke

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top