Winn.ws

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

The OO way of JavaScript

This is something I picked up in making my own functions and trying not to effect my other js libraries. I first start by creating a base function like so:

function Wrapper() {
 
}

Then inside that function I create my “methods” if you will…

function Wrapper() {
     this.MyMethod = function(var) {
          return var;
     }
}

Once I am done creating the methods I now need to call my new javascript methods, I can do this by creating a new instance of my function that wraps the methods.

var MyScript = new Wrapper();

After creating the new instance I can now call my methods.

MyScript.MyMethod('Some Text');
posted in: Development, web standards 10.28.08