How to get current URL parameters and Hash tag using JQuery and JavaScript

While dealing with current URL, many time you want to know what is the current URL path, What are the parameters, and what is the hash tag on URL. Hash tag is pretty important, if you are implementing tab structure using HTML and JQuery. To avoid confusion, let's take an example of URL: http://javarevisited.blogspot.com/2013/01/top-5-java-programming-books-best-good.html#ixzz2PGmDFlPd, in this example ixzz2PGmDFlPd is hash tag. Now, both JavaScript and JQuery provides convenient way to retrieve current URL in form of window.location object. You can use various properties of window.location JavaScript object e.g. window.location.href to get complete URL, window.location.pathname to get current path, and window.location.hash to get hash tag from current URL. If you like to use JQuery then you can get window.location as JQuery object and retrieve relevant properties using attr() function. If you are absolutely new in JQuery, and unaware of power of one of the most popular JavaScript framework, Head First JQuery is a good starting point. Being a fan of head first book, I always approach a new technology by an Head first title, it helped to learn a lot in short time, without spending time in trivial examples. By the way, In this web tutorial, we are going to retrieve current URL and hash tag using JavaScript and JQuery.
Read more »

Related Posts by Categories

0 komentar:

Posting Komentar