views:

46

answers:

4

Given an URL such as /abc.html#variable1, I want to capture the variable1 part to determine a given user's "virtual page" when working with JavaScript (jQuery).

A: 

Examine the window.location.hash. Not jQuery specific.

alex
A: 

You can use window.location.hash to get the value after the # sign.

You can find some information on the topic here. And within the context of unique URLs for AJAX, you can check out this extensive article.

Ryan Emerle
A: 

I'm not sure if this is what you are asking for, but the way to retrieve the page's url is:

var pathname = window.location.pathname;

It is really javascript, no jQuery involved. If you want to addd some jQuery:

$(document).ready(function() {
    var pathname = window.location.pathname;
});

Hope it helps.

yinyang78
+1  A: 

If I understand your question, you don't need at all jquery, just use

to get the url use

var the_link = document.location

to get just the hash part of the url (the text after #) use

var the_hash = document.location.hash 

to get the GET variables you can use

var get_vars = document.location.search
Eineki
Thanks it works but i am linking from same page for example i have abc.html#varible1 link on abc.html. In this case it does not catch click event vice verse if i go to abc.html#varible1 via browser address line or from another page it works. How can i fix that ? Thanks
mTuran
@mTuran: Maybe you should check this page http://benalman.com/code/projects/jquery-hashchange/docs/files/jquery-ba-hashchange-js.html
Eineki