Friday, 5 August 2011

Using Fiddler with HTTPS

By default Fiddler doesn't allow you to view and inspect the details of requests made via HTTPS.

This can be done if you enable "Decryption of HTTPS traffic"

Go to Tools >> Fiddler Options >> Select HTTPS tab >> Select "Decrypt HTTPS traffic" if it is not already selected.

When you select this option Fiddler will popup two warning message boxes, one after the other. First one will say something like "Fiddler generates a root CA certificate to intercept HTTPS traffic". Click "Yes" then it will popup another message box saying "You are about to install a certificate from CA...". Click "Yes" again.

That is it. You can start debugging HTTPS traffic now.

http://www.fiddler2.com/fiddler/help/httpsdecryption.asp

Thursday, 4 August 2011

Disable hardware acceleration in Firefox

When dual monitor is used, and firefox is on the second monitor, the Firefox menu doesn't show up. Same happens to the address bar when typing previously visited sites.

If you experience this problem disabling hardware acceleration might fix it.

To disable hardware acceleration in Firefox follow below steps

In the Options window, select the Advanced → General tab.

Then un-check the checkbox labeled "Use hardware acceleration when available".

Click OK

Friday, 29 July 2011

jQuery Plug-ins : how to build?

Plugin Authoring Guidelines
http://docs.jquery.com/Plugins/Authoring

Building Your First jQuery Plugin
http://blog.jeremymartin.name/2008/02/building-your-first-jquery-plugin-that.html

A Plugin Development Pattern
http://www.learningjquery.com/2007/10/a-plugin-development-pattern

Wednesday, 27 July 2011

Hiding JavaScript code from older browsers

It is straighforward, follow the steps below:

1. Immediately after the opening <script> tag, put a one-line HTML-style comment without the closing characters, so that the first two lines of your script would look like this:

<script language="JavaScript">
<!--


2. At the end of your script, put the following two lines:

//-->
</script>


Thus, your HTML file will contain the following fragment:

<script language="JavaScript">
<!--
Here you put your JS code.
Old browsers will treat it
as an HTML comment.
//-->
</script>

Old browsers will treat your JS code as one long HTML comment. On the other hand, new JavaScript-aware browsers will normally interpret JS code between the tags <script> and </script> (the first and last lines of your JavaScript code will be treated by the JavaScript interpreter as one-line comments).

Tuesday, 26 July 2011

Auto-boxing JavaScript primitive types

Primitive Types in JavaScript

Number values, like 1,
string values, like "",
the boolean values true and false,
and the special values null and undefined

Object types in JavaScript

Date objects,
regular expression objects,
function objects,
arrays
and literal objects like {}

Auto-boxing
Whenever you access or assign to a property of a number, string or boolean, a temporary object value (of the Number, String or Boolean class, respectively) is created with the same naked value as the primitive value, but that temporary object is only available to that property access, and does not replace the primitive value that your variable references.

Example

Calling split() on primitive value.


var str = 'primitive-valued string literal';
console.log( str.split(' ') ); //=> obviously ["primitive-valued", "string", "literal"]
str.split = function(){ return 'overridden!'; };
console.log( str.split(' ') ); //=> still ["primitive-valued", "string", "literal"]


Calling split() on String object.


var str = new String( 'primitive-valued string literal' );
console.log( str.split(' ') ); //=> obviously ["primitive-valued", "string", "literal"]
str.split = function(){ return 'overridden!'; };
console.log( str.split(' ') ); //=> "overridden!" that's more like it


Read more >>

Debugging JavaScript using Firebug console

Sometimes the fastest way to find bugs is just to dump as much information to the console as you can. Firebug gives you a set of powerful logging functions that you can call from your own web pages.

console.log

The easiest way to write to the Firebug console looks like this: console.log("hello world")

You can pass as many arguments as you want and they will be joined together in a row, like console.log(2,4,6,8,"foo",bar).

Logging object hyperlinks

console.log and its related functions can do a lot more than just write text to the console. You can pass any kind of object to console.log and it will be displayed as a hyperlink. Elements, functions, arrays, plain ol' objects, you name it. Clicking these links will inspect the object in whatever tab is most appropriate.

String formatting

console.log can format strings in the great tradition of printf. For example, you can write console.log("%s is %d years old.", "Bob", 42).

Color coding

In addition to console.log, there are several other functions you can call to print messages with a colorful visual and semantic distinction. These include console.debug, console.info, console.warn, and console.error.

console.log() and older browsers



You can write a script which creates console functions if they don't exist. For example following script can be used to alert the given value when console.log() is unavailable.


<script type="text/javascript">

if (!window.console) console = {};
console.log = console.log || function(s){alert(s)};

console.log('testing')

</script>



Click here to read more

JavaScript For...In Statement

The for...in statement loops through the properties of an object.

Syntax


for (variable in object)
{
//code to be executed
}


Note: The code in the body of the for...in loop is executed once for each property.

Example

Looping through the properties of an object:


<script type="text/javascript">

var person={fname:"prince",lname:"thomas",age:30};

for (var property in person)
{
document.write(property + ": " + person[property] + "<br>");
}
</script>


The output will be

fname: prince
lname: thomas
age: 30