开发者

How can I extract tokens from the current URL using JavaScript

开发者 https://www.devze.com 2022-12-19 06:41 出处:网络
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 y

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号