1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

jQuery Fit Footer To Window Height


Sometimes your content just doesn't fit the window height, for exampling when you're styling a page with placeholder content. Or, for a short post like this.

That's why I use the script below for making sure my footer appears at the bottom of pages where the content is shorter than the window:

function AdjustWindowHeight()
    var requiredHeight = $(window).height() - $("#footer").height();
    $('#wrap').css('min-height', requiredHeight);

$(window).on("resize", AdjustWindowHeight);

$(function () {

Or the minified version:

function F(){var a=$(window).height()-$("#footer").height(); $("#wrap").css("min-height",a)}$(window).on("resize",F);$(function(){F()});

All you need is a div containing all your footer content and and wrap div containing all other content:

<div id="wrap">Content</div>
<div id="footer">Footer :)</div>



JSON.NET by James Newton-King is the library for working with JSON in .NET. The following is a small guide for using JSON.NET. It is in no way a substitute for the full documentation.

To follow along obtain the JSON.NET package using NuGet and the Newtonsoft.Json dll will be added to your project's references. Alternatively download from the official website and add the reference manually.

Serialize An Object And De-serialize

Serialization is the process of translating data structures or object state into a format that can be stored - Wikipedia.

We will start our investigation with a very simple C# object and continue from there. As always, we are using the Dog class:

public class Dog
    public int Id { get; set; }
    public string Name { get; set; }
    public string Breed { get; set; }
    public DateTime Birthday { get; set; }

    public int CalculateAgeInDays()
        return (DateTime.Now - Birthday).Days;

This is very simple class but might mirror something you need to serialize.

To start, let's create a dog and convert it to a string of Json (which I'll stop capitalising because it's a pain to type).

Dog dog = new Dog
    Id = 4,
    Breed = "Labradoodle",
    Name = "Baron Von Lassie",
    Birthday = Convert.ToDateTime("2013-01-07"),
string json = JsonConvert.SerializeObject(dog);

The string that we obtain is 'minified':

{"Id":4,"Name":"Baron Von Lassie","Breed":"Labradoodle","Birthday":"2013-01-07T00:00:00"}

As you can see all extraneous whitespace and extra line-breaks have been removed. This is ideal for data transfer objects such as a response from a Web Service, however if we're trying to present our data in a human readable way it's nicer to set Formatting.Indented like so:


What Is JSON?


This is intended as a simple guide to JSON.

The more programming you do the more you hear about the data format "JSON".

However I've never actually used it until the changes to ASP.NET in vNext encouraged me to use it, basically the old XML format of the Web.Config is out and JSON is in (though you can swap back if I recall correctly).

What's In A Name?

JSON stands for "JavaScript Object Notation".

JavaScript Objects

The origin for this name is clear when you consider JavaScript objects. JavaScript objects are effectively dictionaries of key value pairs.

For those of you not familiar with a dictionary, the concept of JavaScript objects is as follows.

Let's describe your house:

var yourHouse = {
    number : 25,
    numberOfWindows : 20,
    name : "Honeysuckle Cottage",
    dog : new Dog(),
    openDoor : function() {

Now this isn't the best way to express a JavaScript Object with methods (or at all for that matter) but it expresses that JS objects are just collections of names for things and their values.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18