-1

I have a url

http://localhost:8162/UI/UsersDetail.aspx?id_temp=U0001

I want to get string use javascript

?id_temp=U0001

Thank guys.

Headshot
  • 423
  • 1
  • 6
  • 22

2 Answers2

1

If this isn't the location of the page, you may use

var str = url.match(/\?.*$/)[0];

If this url is the current one of your page, use

var str = location.search;
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0

You can use regex:

url.match(/\?(\w+=\w+)/)[0];
  1. / : Delimiter of regex
  2. \? : Matches ? need to escape using \
  3. \w+: Matches all alphanumeric characters and _
  4. = : Matches =
Tushar
  • 85,780
  • 21
  • 159
  • 179