Any Other BusinessS2C Home « Any Other Business

This lesson wraps up our journey into the world of JavaScript by looking at the globals and statements not covered in previous lessons.

Encoding & Decoding URIs


We can encode a uri using the encodeURI global function. This function will encode special characters within the URL, apart from those parts used by component parts of the uri, such as user parameters.

We can also decode any previously encoded uri using the decodeURI global function. This function will decode special characters within the URL, apart from those parts used by component parts of the uri, such as user parameters.

Below is an example of using the encodeURI global function to encode special characters. After this we decode the uri we encoded using the decodeURI global function. We should end up with the same uri we had before we encoded and then decoded it.


// Encode and then decode a uri 
var uri="a spurious name.com?firstname=barney&surname=magrew";
alert(encodeURI(uri));
alert(decodeURI(uri));  

Press the button below to action the above code:


Encoding & Decoding Component URIs


We can encode a uri using the encodeURIComponent global function. This function will encode special characters within the URL and component parts of the uri, such as user parameters.

We can also decode any previously encoded uri using the decodeURIComponent global function. This function will decode special characters within the URL as well as component parts of the uri, such as user parameters.

Below is an example of using the encodeURIComponent global function to encode special characters. After this we decode the uri we encoded using the decodeURIComponent global function. We should end up with the same uri we had before we encoded and then decoded it.


// Encode and then decode a uri 
var uri="a spurious name.com?firstname=barney&surname=magrew";
alert(encodeURIComponent(uri));
alert(decodeURIComponent(uri));  

Press the button below to action the above code:


The debugger statement

The debugger statement starts up any available debugging functionality, or does nothing if no debugging functionality available.

The code below invokes a debugging tool if functionality available. For instance if you have Firebug installed on Firefox this will be launched when code is run.


function goDebugger()
{
  debugger;
  alert('In debugger');
} 
goDebugger();

Press the button below to action the above code:


Lesson 9 Complete

In this lesson we looked at encoding and decoding URIs and the debugger statement.

What's Next?

I really hope you have learnt from these JavaScript tutorials. A comprehensive reference section for JavaScript follows these tutorials.

Fuelled with the knowledge gained in JavaScript we are now ready to take a journey into the wonderful world of jQuery 1.10 which is discussed in the next part of the site.

go to home page Homepage go to top of page Top