2012-02-12 108 views
2

我想擺脫URL信息使用jQuery:獲取URL的一部分使用jQuery

login 

從這個網址:

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

所以我想什麼,是讓來自# 的信息以及稍後使用我從#獲得的信息製作包含。 我知道如何包含一個文件,但我不知道如何從網址獲取信息,並從「#」

我不是真的想用& site = login,因爲這是我的最後一個選項。

回答

4

爲什麼不使用window.location.hash

0

window.location對象有一個hash屬性。

console.log(window.location.hash); 

分手的值,如果有多個具有:

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

使用jQuery

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

謝謝,它的工作原理。 – Kristjan 2012-02-12 14:43:24

+2

@Kristjan:哇,我正在諷刺,用[karim79's](http://stackoverflow.com/a/9249432/465546)回答。我的方式是[Rube Goldberg](http://en.wikipedia.org/wiki/Rube_Goldberg_machine)方式。你不需要這個jQuery。 – qwertymk 2012-02-12 18:19:41