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).
views:
46answers:
4
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
2010-02-04 00:49:56
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
2010-02-04 00:53:47
+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
2010-02-04 00:55:59
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
2010-02-04 01:44:18
@mTuran: Maybe you should check this page http://benalman.com/code/projects/jquery-hashchange/docs/files/jquery-ba-hashchange-js.html
Eineki
2010-02-05 00:40:44