Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...How to add javascript in the head tags of dnn 4.9 How to add javascript in the head tags of dnn 4.9
Previous
 
Next
New Post
6/11/2010 10:14 AM
 
My first attempt at posting a reply appears to have been "eaten"...so I'll give it another go.

I don't know if you're still looking for a solution to this issue, but a solution that has worked well for us is to use the RegisterClientScriptBlock method to inject your javascript (or RegisterClientScriptInclude to write an external reference to your source .js file) into the head section of the page. 

To do this add a code-behind file to your skin.ascx file (or, alternatively, you can add the following to your skin.ascx file inline using <script runat="server"> tags.  (The following is in C#.

public partial class MainSkin : DotNetNuke.UI.Skins.Skin
{
    protected void Page_Load(object sender, EventArgs e){
        System.Web.UI.ClientScriptManager CSM = new ClientScriptManager();
        CSM.RegisterClientScriptInclude("Key",SkinPath + "js/source.js");
    }
}

The important part is what appears in the Page_Load event.  The "Key" is a name that you can assign to that particular script include that you can use to check if you've already loaded the script with that "key" on the page using the CSM.IsClientScriptIncludeRegistered("Key"); should you be trying to load the .js from a container file rather than the skin file.  That way, the javascript is injected only once, regardless of how many times a container may appear on your page.  This would more commonly be done through custom user controls, but if you had a special container that made use of a rather large jQuery plugin that you only wanted to load if the container was present on the page, this would serve that need.

Obviously, the second parameter in the method above is the path to your js file, starting from the SkinPath.

I hope that helps.
 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...How to add javascript in the head tags of dnn 4.9 How to add javascript in the head tags of dnn 4.9


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out