Winn.ws

Loading content with JQuery

Loading content via Ajax is quick and easy with JQuery. If you have never used jQuery before you might think twice about it!

Below is my html where we will load the content.

1
<div id="LoadContent"></div>

Now lets look at the javascript needed to load a remote page in.

1
$("#LoadContent").load("path/to/remote/file.php");

After that is called the contents of “file.php” would be loaded into the div above! Quick and easy way to include item into your app. You may also pass variables to the page like so:

1
$("#LoadContent").load("path/to/remote/file.php", {id: 1, name: "Greg"});

Hope this small tool helps change your mind about JQuery!

posted in: Development 03.30.09

Browser detection using jQuery

Browser sniffing is messy. There are a million ways to do it but none of them are particularly clean and most involve conditional statements such as “” for IE and various other CSS selector hacks for other browsers.

It get around this common issue i am now using jQuery to add a class to my body tag.

1
2
3
4
5
if($.browser.msie){
        $('body').addClass('browserIE');
        // Add the version number
        $('body').addClass('browserIE' + $.browser.version.substring(0,1));
}

If the user is using IE it will add a class to teh body tag like so:

1
<body class="browserIE browserIE#">

The “#” stands for the version of IE the user is running.

You can now access elements on your page that neeed to be corrected for IE by calling:

1
2
3
.browserIE6 #myDiv {
     display:block;
}

This will work much better then current hacks. Hope that helps someone!!

posted in: Development 02.10.09

Cookies with JQuery

So in some of my latest projects i dont have full source access, so i need to look for cookies the main application is setting. To do this i am using jQuery to look into the cookies and give me the value. Once i know the value i can then write a new cookie that the main application will see and use.

Below is an idea of what i am doing to read the cookies from the main application.

1
2
3
4
if($.cookie('Cookie_name')) {
     var MainAppCookie = $.cookie('Cookie_name');
     $.cookie('NewCookie_' + MainAppCookie , 'Value');
}

To use the $.cookie i am using a simple plugin for jQuery. This allows me to access the cookies quick and easy. Now if the application gives me a special cookie i can then delete my old ones by doing this…

1
2
3
if($.cookie('Cookie_name') == 'Special Text') {
     $.cookie('MyCookie', null, {-1}); // This will delete the cookie
}
posted in: Development 02.09.09

jQuery to Ship with Visual Studio

Microsoft will now be adopting jQuery for all it’s Ajax tools and any javascript related items. This is a big win for jQuery!

We have two pieces of fantastic, albeit serendipitous, news today: Both Microsoft and Nokia are taking the major step of adopting jQuery as part of their official application development platform. Not only will they be using it for their corporate development but they will be providing it as a core piece of their platform for developers to build with…

Read more of this at the jQuery Blog>>

posted in: .NET 3.5 VB, Development 10.01.08