Kristjan
Kristjan

Reputation: 113

Getting a part of URL with jQuery

I would like to get this information from url with jQuery:

login

from this url:

http://www.domain.com/index.html#login

So what i would like, is to get the information from # and later use the information that i got from # to make an include. I know how to include a file, but i don't know how to get the information from the url, and from "#"

I don't really want to use &site=login, because it's my last option.

Upvotes: 2

Views: 171

Answers (4)

qwertymk
qwertymk

Reputation: 35256

With jQuery

var loc = $(window)[0].location;
var thingYouWant = $(loc).prop('hash').substr(1);

Upvotes: 0

osahyoun
osahyoun

Reputation: 5231

The window.location object has a hash property.

console.log(window.location.hash);

Break up the values, if there are multiple with:

window.location.hash.split('#');

Upvotes: 0

Dmitry Kudryavtsev
Dmitry Kudryavtsev

Reputation: 17584

Why not use window.location.hash ?

Upvotes: 4

karim79
karim79

Reputation: 342635

Pure JS:

console.log(window.location.hash);

Upvotes: 4

Related Questions