3

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?

Linton Caldecott
  • 449
  • 6
  • 17
  • Ok. Update time! I managed to get this displaying on all pages, loading the javascript with it, except where I REALLY need it is when I click login or register! It's not there. How do I get my javascript to load in those modules/pages... whatever they are. – Linton Caldecott Aug 29 '13 at 13:21

5 Answers5

5

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
Chris Hammond
  • 8,873
  • 1
  • 26
  • 34
  • Ok. Update time! I managed to get this displaying on all pages, loading the javascript with it, except where I REALLY need it is when I click login or register! It's not there. How do I get my javascript to load in those modules/pages... whatever they are. – Linton Caldecott Aug 29 '13 at 13:20
  • Unfortunately those aren't yet "pages" they are just DNN loading the register/login controls. So you'll need to create two pages (one for each) and place the Account Login and Registration modules on those pages. Then on the Admin/Site Settings choose those as the Login and Register page in the dropdown list section. – Chris Hammond Aug 29 '13 at 14:41
  • Hi Chris. I am not trying to set up my own site. The goal is to create a module that is easily downloadable and configurable. I need to interface with both login and registration. First I tried creating an authentication provider, and that was fine but didn't accomplish the registration requirements, the other plugins that my colleagues created for joomla etc, just inject javascript into each page (hence this query), but it appears that won't work either. So I'm feeling a bit stuck now. I could get things working on my own site, but that doesn't really fit to the request for a plugin. – Linton Caldecott Aug 30 '13 at 06:45
  • Will modifying the skin include javascript to those generated login and registration modules? I could set up a config doc to help clients include our javascript into their skin (if doing that would accomplish our goals) – Linton Caldecott Aug 30 '13 at 07:08
  • Yes, modifying the skin will include the JS on every page that uses that skin, including the register/login pages – Chris Hammond Aug 30 '13 at 18:53
  • Thanks for the feedback. Can you point me to what files I should be looking at in DNN7. The sites I have been looking at just suggest I put specific code in "the skin files", and as I think I have mentioned I am a n00b to DNN and I need more granular direction than just "the skin files" – Linton Caldecott Sep 02 '13 at 11:32
  • /portals/_default/skins/SKINNAME/SOMETHING.ascx – Chris Hammond Sep 04 '13 at 03:36
2

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.

Mitchel Sellers
  • 62,228
  • 14
  • 110
  • 173
  • Have you any pointers for me to look through to do this. I am a couple week old dnn noob. I'm trying to create a means for people to download a plugin from the store so our login method will work with the least amount of manual admin. I created a custom auth module, but then registration is a problem, as far as i can see you can't create a custom registration provider like you can do with an authentication provider, which is pretty annoying. So now I am looking at loading javascript on every page and hooking in to the controls that way... but the login generated page still defies my attempts! – Linton Caldecott Aug 29 '13 at 13:45
1

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> 
ransems
  • 641
  • 7
  • 19
  • Well, thanks for this answer, I have not touched DNN since 2013 so I couldn't test your answer! But it sure looks easier and less hacky than the way I came up with. – Linton Caldecott Jul 07 '20 at 07:44
0

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

Rob Schmuecker
  • 8,934
  • 2
  • 18
  • 34
0

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.

Linton Caldecott
  • 449
  • 6
  • 17