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

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...skin javascript clock on page loadskin javascript clock on page load
Previous
 
Next
New Post
8/2/2013 8:24 PM
 

I started building a new skin from the html 5 boilerplate.  On the user/login menu, when the page loads, I'd like to display the output of a simple javascript clock I wrote.  I am new to skinning and javascript, so this may be simple and I just don't know.

Outside the skin elements, just below an identical reference to main.js, I have referenced the external clock.js file (which is in the skin's js folder):

<script type="text/javascript" src="<%skinpath %>""js/clock.js"></script>

and the javascript file references the correct div id in the skin "date".

 the script itself is functional, but will not display the clock in the skin, I would like the clock to fire on the page load, and I don't know how to do it. Here is the entire js file, what am I missing, please help.

clock.js:

function clock() {

    var today = new Date();

    var day = today.getDate();

    var month = today.getMonth() + 1;

    var year = today.getFullYear();

    var h = today.getHours();

    var m = today.getMinutes();

    var s = today.getSeconds();

    var ampm;

    // Set ampm

    ampm = apMeridian(h);

    // Format the hours

    h = formatHours(h);

    // Format minutes and seconds

    m = formatMS(m);

    s = formatMS(s);

    document.getElementById("date").innerHTML = day + " " + month + " " + year + " " + h + ":\

" + m + ":" + s + " " + ampm;

    t = setTimeout(function () { clock() }, 250);

}

 

function formatHours(i) {

    if (i >= 13) {

        i = i - 12;

    }

    else if (i = 0) {

        i = 12;

    }

    return i;

}

 

function formatMS(i) {

    if (i < 10) {

        i = "0" + i;

    }

    else { }

    return i;

}

 

function apMeridian(i) {

    var ap;

    if (i <= 11) {

        ap = "am";

    }

    else {

        ap = "pm";

    }

    return ap;

}

 

Thank you for your help!

 
New Post
8/3/2013 2:17 AM
 

Have you first checked if the jQuery is loaded on your ascx control?

 <script runat="server">

     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

DotNetNuke.Framework.jQuery.RequestRegistration()
DotNetNuke.Framework.jQuery.RequestUIRegistration()

End Sub
script>

 

 
New Post
8/3/2013 11:09 AM
 

Hi,

try this:

Dim body As System.Web.UI.HtmlControls.HtmlGenericControl = CType(Page.FindControl("body"), System.Web.UI.HtmlControls.HtmlGenericControl) body.Attributes("onload") = clock()

This should load the clock() in the body onload tag.

Hope this helps 


      
 
New Post
11/20/2013 8:21 AM
 
Thank you both for the answers. I have been locked out of my account since I posted this originally. I wanted to ask Mr. Schlomann, the code you passed on, does that go directly into the skin control, and am I calling the admin/skins/jQuery.ascx module/control/token/thingy for use in the skin? If so, it's starting to make sense. I did finally find a way to make the clock work, I actually just wrote out the entire clock script at the bottom of the skin control "default.ascx", and it works great, I am unsure about whether or not this is safe or a bad practice though. Any thoughts? Also, would I use your script in order to call jQuery in general when building skins?
Mr. Barlow, I am unsure where your code would go at all. I still have yet to find a code behind file that is actually attached to the skin control in any way. In my skin folder, for each control I have, there is an .ascx control, and and xml doctype file, but no ascx.cs/ascx.vb file to speak of. Should I create a new DNN token in admin/skins (that would be cool, I don't know how to do that exactly, but would like to learn) and then call it?
Thank you both again.
 
New Post
11/21/2013 4:49 AM
 

My code snipe can be added to the Header of the Skin ascx controls. It checks if the jQuery is allready loaded and if not it loads it.  This have only to be added to Skin controls if you have own JavaScript in your Skin control added or loaded from a subfolder in your Skin.

About on each Skin control you have registered other controls on the top you did not need any code behind.  If you want to change the code behind you should develope a skinobject install them and Register it on your Skin ascx controls.

 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...skin javascript clock on page loadskin javascript clock on page load


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