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, ...Adding Javascript after JQuery libraryAdding Javascript after JQuery library
Previous
 
Next
New Post
8/22/2011 1:40 AM
 

Is there any way to add Javascript after the JQuery library (jquery.min.js) in a skin file.
DNN version 5.1.4

I’d like to achieve this without the use of any plugins – just editing the .ascx file.

I'd like the Head of the page to render as below:

<head id="Head">
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <meta content="text/javascript" http-equiv="Content-Script-Type" />
    <meta content="text/css" http-equiv="Content-Style-Type" />

<link href='/Portals/_default/Skins/Website/css/main.css' rel='stylesheet' type='text/css' />
<link href='/Portals/_default/Skins/Website/css/menu.css' rel='stylesheet' type='text/css' /

<script type="text/javascript" src="/Resources/Shared/Scripts/jquery/jquery.min.js" ></script>
<script type="text/javascript" src="/portals/_default/Skins/Website/js/custom.js"></script>

<title>Name Title</title>
</head>


Current skin file - sample.ascx (need to add code to embed custom.js):

<script runat="server">
 Protected Overrides Sub OnLoad(ByVal e As EventArgs)
  MyBase.OnLoad(e)
  AttachCustomHeader("<link href='" + SkinPath + "css/main.css' rel='stylesheet' type='text/css' />")
  AttachCustomHeader("<link href='" + SkinPath + "css/menu.css' rel='stylesheet' type='text/css' />")
 End Sub

 Sub AttachExternalCSS(ByVal CSSPath As String)
  AttachCustomHeader("<link type='text/css' rel='stylesheet' href='" & CSSPath & "' />")
 End Sub
 
 Sub AttachExternalJS(ByVal JSPath As String)
  AttachCustomHeader("<script type='text/javascript' src='" & JSPath & "'></scr" & "ipt>")
 End Sub
 
 Sub AttachCustomHeader(ByVal CustomHeader As String)
  Dim HtmlHead As HtmlHead = Page.FindControl("Head")
  If Not (HtmlHead Is Nothing) Then
   HtmlHead.Controls.Add(New LiteralControl(CustomHeader))
  End If
 End Sub
</script>


Any help would be greatly appreciated.
Many thanks.

 
New Post
8/22/2011 2:24 AM
 
You can use our "Style Helper" skin object for that or check the code used to inject the JS: http://dnnskinextensions.codeplex.com...
 
New Post
8/22/2011 9:08 AM
 

Thanks Timo but could someone please be so kind to post the code to add Javascript (custom.js) after the JQuery library (jquery.min.js)?

Thanks.

 
New Post
8/22/2011 11:43 AM
 
Ok as the source is with the skin object I exprected you to get is from there is you needed it.

In short, you should use:
Private Sub Page_PreRender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.PreRender

And not on_load
 
New Post
8/22/2011 11:48 AM
 
And you can use this to make sure your adding at the end of the head:

oHead = Me.Page.FindControl("Head")

    If Not oHead Is Nothing Then
        oHead.Controls.AddAt(oHead.Controls.count, "Your literal")
    End If
 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...Adding Javascript after JQuery libraryAdding Javascript after JQuery library


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