How can I extract tokens from the current URL using JavaScript
Given an URL such as /abc.html#variable1
, I wa开发者_StackOverflownt to capture the variable1
part to determine a given user's "virtual page" when working with JavaScript (jQuery).
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
Examine the window.location.hash
. Not jQuery specific.
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.
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.
精彩评论