Extracting cookies using Javascript

Cookies in the current page can be extract using Javascript using ‘document.cookies’ which returns a ‘;’ separated String of all the current cookie values.

You can parse the values with some script like this:

function getCookie(name) {
    var result = '';
    var cookies = document.cookie.split(';');
    for ( var i = 0; i < cookies.length; i++) {
        //alert(cookies[i]);
        var cookie = cookies[i].split('=');
        if (cookie[0].replace(/^s+|s+$/g, '') == name)
            result = cookie[1];
    }
    return result;
}

Fixing Twitter Bootstrap rendering issues in Internet Explorer

Internet Explorer’s interpretation of CSS compared with all the other browsers sometimes bewilders me. To get Twitter Bootstrap to render at all like the other browsers, apparently it’s important that you have to specify the doctype, otherwise it seems to render layout related CSS all over the place. Just include this at the top of your source:

<!DOCTYPE HTML>

I found this as an answer to this post on StackOverflow.

Things you always forget: XML Character Entities

Certain characters break XML or need to be escaped in HTML so they are rendered literally and not interpreted themselves as markup. There’s a few predefined character entities that are commonly used:

  • &lt;      :     <
  • &gt;     :     >
  • &amp; :    &

For other characters though, you sometimes need to use their Unicode encoded value. For example to literally display { and } in a JSP or JSF page (since they are used in EL syntax ${} and #{} ), you can use their unicode values like this:

  • &#x007b;     :     {
  • &#x007d;     :     }

There’s many unicode ref charts online, here’s one that I’ve used:

http://en.wikibooks.org/wiki/Unicode/Character_reference/0000-0FFF