The document.cookie Property is available in DOM for accessing cookie values in javascript. This Property returns all of the cookies in a long semicolon separated string. For example:
cookie1=value1; cookie2=value2; cookie3=value3; ...
There is no way of accessing individual cookie values like we access Request variables on the server side. You must extract the required cookie value from one long string. It can be easily done with a few lines of code, but if you like the way things work on the server side, here is a small helper Javascript function I wrote to prepare a dictionary with all cookie values. Now instead of trying to extract value from a long string, you can use the following code:
var cookies = getCookies();
var value1 = cookies["cookieName"];
//Now value1 holds the value of cookie "cookieName"
Makes things easier especially when multiple cookies are in use. Here is the helper function that prepares a dictionary with all available cookies and values:
function getCookies()
{
var cks = new Object();
var ckList = document.cookie.split("; ");
for (var i=0; i < ckList.length; i++)
{
var ck = ckList[i].split("=");
cks[ck[0]] = unescape(ck[1]);
}
return cks;
}
This code has been used in several places without any problems. If you encounter any issue, please post a comment.
Posted on February 11, 2010 09:50 by
Haider
It is possible to show interactive driving directions on your Website with very minimal effort. Google Maps now includes the driving directions API, and you could embed driving directions and maps on your Website for free.
Like all other GoogleMaps feature, you are required to obtain an API key, which is free too.
We have integrated this into our Driving Directions at houselocator.com, here is an example:
http://www.houselocator.com/DrivingDirections.aspx?ID=15274&Street=&Zip=34741
One advantage of Javascript API integration is, as Google keeps adding more features, they will automatically appear on your Website. Right now, they have a nice way of zooming into any turn on the directions. Just click on a step in the directions in the example above and see it in action.
Check out the Google Maps API at: http://www.google.com/apis/maps/
Integration is really easy.
** Update: I have written a GoogleMaps Directions API wrapper control for ASP.NET that you can use to easily integrate driving directions in your ASP.NET projects. Check the following post:
GoogleMaps-Driving-Directions-API-Wrapper-Control-for-ASPNET
Posted on October 27, 2007 13:44 by
Haider