开发者

js, how to get one part in location.hash

开发者 https://www.devze.com 2023-04-03 04:46 出处:网络
I want to get the location.hash part, the word after first %20. But how? For explain http://localhost/text/search.php?search=sweet%20girl=> girl

I want to get the location.hash part, the word after first %20. But how?

For explain

http://localhost/text/search.php?search=sweet%20girl  => girl
http://localho开发者_Go百科st/text/search.php?search=fashion  => NULL
http://localhost/text/search.php?search=2011%20best%20and%20worst => best and worst


var s = decodeURIComponent(location.search);
var index = s.indexOf(" ");
s = index === -1 ? s.substr(index + 1) : null;


Use the unescape function first. After that you can do a regexp replace.

var url = "http://localhost/text/search.php?search=2011%20best%20and%20worst";
alert (unescape(url).replace(/^\S* /,""));
0

精彩评论

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