How to extract tokens from the current URL using JavaScript

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

+3
source share
4 answers

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

to use the url

var the_link = document.location

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

var the_hash = document.location.hash 

to get get variables that you can use

var get_vars = document.location.search
+1
source

Explore window.location.hash. Not specific to jQuery.

0
source

window.location.hash, #.

. URL- AJAX .

0

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

var pathname = window.location.pathname;

This is really javascript not involved in jQuery. If you want to add some jQuery:

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

Hope this helps.

0
source

Source: https://habr.com/ru/post/1731300/


All Articles